Ada 3 macam bentuk piramid yaitu piramid tengah, kanan, dan kiri.
SOURCE CODE BINTANG PIRAMID TENGAH
//BINTANG PIRAMID TENGAH
public class Bintang
{
public static void main(String[] args)
{
int bintang;
int spasi;
int baris = 5;
for(bintang = 1; bintang <= baris; bintang++)
{
for(spasi = 5; spasi >= bintang; spasi--)
{
System.out.print(" ");
}
for(int a = 1; a <= bintang; a++)
{
System.out.print("* ");
}
System.out.println("");
}
System.out.println("");
}
}
OUTPUT
SOURCE CODE BINTANG PIRAMID KANAN
//BINTANG PIRAMID KANAN
public class BintangKanan
{
public static void main(String[] args)
{
int bintang;
int spasi;
int baris = 5;
for(bintang = 1; bintang <= baris; bintang++)
{
for(spasi = 5; spasi >= bintang; spasi--)
{
System.out.print(" ");
}
for(int a = 1; a <= bintang; a++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
OUTPUT
SOURCE CODE BINTANG PIRAMID KIRI
//BINTANG PIRAMID KIRI
public class BintangKiri
{
public static void main(String[] args)
{
int bintang;
int spasi;
int baris = 5;
for(bintang = 1; bintang <= baris; bintang++)
{
for(int a = 1; a <= bintang; a++)
{
System.out.print("*");
}
System.out.println("");
}
System.out.println("");
}
}
OUTPUT
Terimakasih, Semoga bermanfaat
Sumber from my friend https://serverrendi.blogspot.co.id
0 Response to "Java - Membuat Bintang Piramid"
Post a Comment