- Segitiga
public static void main(String[]args){
int baris;
int batasspasi=4;
int batasbintang=1;
for(baris=1;baris<=5;baris++){
for(int spasi=1;spasi<=batasspasi;spasi++){
System.out.print(" ");
}
for(int bintang=1;bintang<=batasbintang;bintang++){
System.out.print("*");
}
System.out.println();
batasspasi--;
batasbintang+=2;
}
}
2. Segitiga terbalik
public static void main(String[]args){
int baris;
int batasspasi=1;
int batasbintang=9;
for(baris=1;baris<=5;baris++){
for(int spasi=1;spasi<=batasspasi;spasi++){
System.out.print(" ");
}
for(int bintang=1;bintang<=batasbintang;bintang++){
System.out.print("*");
}
System.out.println();
batasspasi++;
batasbintang-=2;
}
}
int baris;
int batasspasi=1;
int batasbintang=9;
for(baris=1;baris<=5;baris++){
for(int spasi=1;spasi<=batasspasi;spasi++){
System.out.print(" ");
}
for(int bintang=1;bintang<=batasbintang;bintang++){
System.out.print("*");
}
System.out.println();
batasspasi++;
batasbintang-=2;
}
}
3. Layang2
public static void main(String[]args){
int baris;
int batasspasi=4;
int batasbintang=1;
for(baris=1;baris<=5;baris++){
for(int spasi=1;spasi<=batasspasi;spasi++){
System.out.print(" ");
}
for(int bintang=1;bintang<=batasbintang;bintang++){
System.out.print("*");
}
System.out.println();
batasspasi--;
batasbintang+=2;
}
for(baris=1;baris<=5;baris++){
batasspasi++;
batasbintang-=2;
for(int spasi=1;spasi<=batasspasi;spasi++){
System.out.print(" ");
}
for(int bintang=1;bintang<=batasbintang;bintang++){
System.out.print("*");
}
System.out.println();
}
}
Tidak ada komentar:
Posting Komentar