Output :
Code :
------------------------------------------
public class Ketupat_2 {
public static void main(String args[])
{
int N, kiri, kanan, I = 0, J = 0, X;
N = 11;
if(N % 2 == 1)
{
X = N / 2;
kanan = X;
kiri = X;
}
else
{
X = (N / 2) - 1;
kanan = X;
kiri = X;
}
while(I <= X)
{
while(J <= N)
{
if(J == kiri)
{
while(J <= kanan)
{
System.out.print("*");
J++;
}
}
else
{
System.out.print(" ");
}
J++;
}
System.out.println();
J = 0;
kiri--;
kanan++;
I++;
}
if(N % 2 == 1)
{
kiri += 2;
kanan -= 2;
}
else
{
kiri += 1;
kanan -= 1;
}
while(I > 1)
{
while(J <= N)
{
if(J == kiri)
{
while(J <= kanan)
{
System.out.print("*");
J++;
}
}
else
{
System.out.print(" ");
}
J++;
}
System.out.println();
J = 0;
kiri++;
kanan--;
I--;
}
}
}
--------------------------------------------
Download contoh.
Penjelasan lebih? Silakan PM ane.
fauzan_adhima_alwan@yahoo.co.id
3 comments:
Suwun banget Jan ya... :)
ga iso di copas zan .. o.O
Yo emang kagak bisa... biar agan ngetik... hehee
setidaknya, saya mengajak agan untuk belajar.. :)
Post a Comment