Membuat bintang segitiga dan segitiga miror
bintang A
*
**
***
****
*****
bintangB
* *
** **
*** ***
**** ****
Jawabannya...
import java.io.*;
class coba2 //JANGAN LUPA NAMA CLASS di samakan dengan nama document anda..
{
public static void main(String[] args) throws Exception
{
BufferedReader in= new BufferedReader (new InputStreamReader (System.in));
int pilih=0;
do
{
System.out.println("=======================");
System.out.println("\tBintang Logor");
System.out.println("=======================");
System.out.println("1. bintang A");
System.out.println("2. bintang B");
System.out.println("3. Keluar");
System.out.print("Pilih : ");
pilih=Integer.parseInt(in.readLine());
System.out.println();
switch (pilih)
{
case 1:
{
System.out.println("Masukan Bintang");
int x=Integer.parseInt(in.readLine());
for (int i=1;i<=x;i++)
{
for (int j=1;j<=x;j++)
{
if(j<=i)
{
System.out.print("*");
}
else
System.out.print(" ");
}
System.out.println();
}
break;
}
case 2:
{
System.out.print("Bilangan pertama : ");
int z=Integer.parseInt(in.readLine());
for (int i=1;i<=z;i++)
{
for (int j=1;j<=2*z;j++)
{
if (j>i && j<=2*z-i)
{
System.out.print(" ");
}
else
System.out.print("*");
}
System.out.println();
}
}
}
System.out.println();
}
while (pilih<3);
}
}
Selasa, 03 Mei 2011
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar