Tuesday, November 13, 2012
Empat Segitiga Siku-Siku
//PATRICIA DIANITA WIJAYA
import java.util.Scanner;
public class SegitigaBintang
{
//patriciadianitawijaya.blogspot.com
public static void main (String [] args)
{
System.out.print("PROGRAM 4 BENTUK SEGITIGA BINTANG");
Scanner input = new Scanner ( System.in );
System.out.print("Pilih segitiga (1,2,3,4) = ");
int x = input.nextInt();
SegitigaSikuBintang1 baru = new SegitigaSikuBintang1();
switch ( x )
{
case 1: baru.Segitia_a();
break;
case 2: baru.Segitia_b();
break;
case 3: baru.Segitia_c();
break;
case 4: baru.Segitia_d();
break; }
}
}
-----------------------------------------------------------------
import java.util.Scanner;
public class SegitigaSikuBintang1 {
public void Segitia_a()
{
int batas, a,b;
Scanner input = new Scanner (System.in);
System.out.print("Masukkan batas = ");
batas = input.nextInt();
for ( a = 0 ; a <= batas ; a++)
{
for (b = 0 ; b < a ; b++)
{
System.out.print("*");
}
System.out.print("\n");
}
}
public void Segitia_b()
{
int batas, a,b;
Scanner input = new Scanner (System.in);
System.out.print("Masukkan batas = ");
batas = input.nextInt();
for ( a = batas ; a >= 0 ; a--)
{
for (b = 0 ; b < a ; b++)
{
System.out.print("*");
}
System.out.print("\n");
}
}
public void Segitia_c()
{
int batas, a,b,c;
Scanner input = new Scanner (System.in);
System.out.print("Masukkan batas = ");
batas = input.nextInt();
for(a=batas;a>0;a--)
{
for(b=a-1;b>0;b--)
{
System.out.print(" ");
}
for(c=batas-(a-1);c>0;c--)
{
System.out.print("*");
}
System.out.print("\n");
}
}
public void Segitia_d()
{
int batas, a,b,c;
Scanner input = new Scanner (System.in);
System.out.print("Masukkan batas = ");
batas = input.nextInt();
for(a=1;a<=batas;a++)
{
for(b=0;b<a;b++)
{
System.out.print(" ");
}
for(c=0;c<batas-(a-1);c++)
{
System.out.print("*");
}
System.out.print("\n");
}
}
}
Tampilan:
Labels:
Pemrograman Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment