-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumber_Diamond.java
33 lines (32 loc) · 984 Bytes
/
Number_Diamond.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
public class Number_Diamond {
public static void main(String[] args) {
int n = 5;
number_diamond(n);
}
private static void number_diamond(int n) {
for(int row = 1; row <= n; row++){
for(int space = 0; space <= n - row; space++){
System.out.print(" ");
}
for (int i = row; i >= 1; i--){
System.out.print(i+" ");
}
for (int j = 2; j <= row; j++){
System.out.print(j+" ");
}
System.out.println();
}
for(int row = n - 1; row >= 1; row--){
for(int space = 0; space >= row - n; space--){
System.out.print(" ");
}
for (int i = row; i >= 1; i--){
System.out.print(i+" ");
}
for (int j = 2; j <= row; j++){
System.out.print(j+" ");
}
System.out.println();
}
}
}