-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssk.java
More file actions
25 lines (23 loc) · 776 Bytes
/
Copy pathssk.java
File metadata and controls
25 lines (23 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public class ssk {
public static void main(String[] args) {
int n = 5; // jumlah elemen per baris
for (int i = 0; i < 5; i++) {
// Cetak spasi di awal baris
for (int j = 0; j < i * 2; j++) {
System.out.print(" ");
}
if (i % 2 == 0) {
// Jika indeks genap, cetak angka
for (int j = 1; j <= n; j++) {
System.out.print(j + " ");
}
} else {
// Jika indeks ganjil, cetak bintang
for (int j = 1; j <= n; j++) {
System.out.print("* ");
}
}
System.out.println(); // Pindah ke baris baru
}
}
}