-
Notifications
You must be signed in to change notification settings - Fork 0
/
UlangDua.java
48 lines (43 loc) · 1001 Bytes
/
UlangDua.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package latihan;
import java.util.Scanner;
public class UlangDua {
public Scanner scan = new Scanner(System.in);
public int getInput() {
System.out.print("Masukkan angka: ");
int bilangan = scan.nextInt();
scan.close();
return bilangan;
}
public void cetakArr() {
int n = getInput();
PolaDeret pola = new PolaDeret();
String[] polaSatu = pola.polaSatu(n);
String[] polaDua = pola.polaDua(n);
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
for (int j = 0; j < n; j++) {
if (j <= i) {
System.out.printf("%3s",polaSatu[j]);
} else {
System.out.printf("%3s"," ");
}
}
System.out.println("");
} else {
int k = 0;
for (int j = 0; j < n; j++) {
if (j <= ((n - i) - 2)) {
System.out.printf("%3s"," ");
} else {
System.out.printf("%3s",polaDua[k]);
k++;
}
}
}System.out.println();
}
}
public static void main(String[] args) {
UlangDua run = new UlangDua();
run.cetakArr();
}
}