Sebelumnya saya sudah membagikan tentang pola piramid, sekarang saya pola piramid yang berbeda pada pemrograman java, .
Selamat mencoba, . .
public class AnotherPyramidPattern {
public static void main(String[] iriahus) {
for (int i = 1; i < 8; i++) {
for (int j = i; j < 7; j++) {
System.out.print(" ");
}
for (int j = 1; j < i; j++) {
System.out.printf(j + " ");
}
for (int j = i; j >= 1; j--) {
System.out.printf(j + " ");
}
System.out.println();
}
System.out.println();
// Displays bonus pattern
for (int i = 0; i < 8; i++) {
for (int j = i; j < 7; j++) {
System.out.print(" ");
}
for (int j = 0; j < i; j++) {
System.out.printf("%4d", (int)Math.pow(2, j));
}
for (int j = i; j < 7; j++) {
System.out.printf("%4d", (int)Math.pow(2, j));
}
System.out.println();
}
}
}
Semoga bermanfaat, .
0 Response to "Membuat Pola Piramida Lain"
Post a Comment