Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Tuesday, March 25, 2014

Membuat Segitiga dengan Java Console

Cara membuat segitiga dengan java Console
segitiga java console
segitiga java console

import java.util.Scanner;

public class bintang
{
	public static void main(String[]args)
	{
		int col, row, a,i ;

		Scanner baca = new Scanner(System.in);

		System.out.print("masukan besar segitiga: ");
		a = baca.nextInt();

		System.out.println();

		for(row = 0 ; row < a; row++)
		{
			for(col = 0; col <=row; col++)
			{
				System.out.print("*");
			}

				System.out.println();
		}

		for(i=0; i<=a; i++)
		 	{
		    for( col=a; col>i; col--)
				{
		      System.out.print(" ");
		  	}

				for( row=1; row<=i; row++)
				{
						System.out.print("*");
		  	}

				System.out.println();
		 	}

		for(i=0; i<=a; i++)
			{
				for( col=a-i; col>0; col--)
				{
					System.out.print(" ");
				}

			for( row=1; row

Contoh Program Menentukan Nilai Tertinggi

berikut contoh program untuk menentukan nilai tertinggi dari suatu bilangan
public class testmax{

 public static void main(String[]args){
  int i = 5;
  int j = 2;
  int k = max(i , j);

  System.out.println("the maximum betwen "+i+ " and "+j+" is "+k);

 }

public static int max(int num1, int num2){
  int result;
  if(num1 > num2)
   result = num1;
  else
   result = num2;

  return result;

 }
}

Monday, March 24, 2014

Menghitung FPB dan KPK Dengan Java Console

Membuat program FPB dan KPK hasila source codenya
import java.util.Scanner;
public class kpkfpb
{
 public static void main(String[] args)
 {
  Scanner baca = new Scanner(System.in);

  int a;
  int b;
  int c;
  int fpb;
  int kpk;
  int x;
  boolean ulang = true;

  do
  {
   System.out.print("\nmasukkan dua buah angka: ");
   a = baca.nextInt();
    baca.nextLine();

   System.out.print(" dan ");
   b = baca.nextInt();
    baca.nextLine();


   x = a * b;
   do
   {
    c = a % b;
    a = b;
    b = c;
   }
   while (b != 0);

   fpb = a;
   kpk = x / fpb;
   System.out.println("\nkpk = "+kpk);
   System.out.println("fpb = "+fpb);


   ulang = true;
  }
  while
  (ulang!=false);

 }
}