forked from PrajaktaSathe/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern7.java
More file actions
33 lines (28 loc) · 754 Bytes
/
Pattern7.java
File metadata and controls
33 lines (28 loc) · 754 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
26
27
28
29
30
31
32
33
package Programs.patterns;
public class Pattern7 {
public static void main(String[] args) {
pattern7(4);
}
// 1
// 2 1 2
// 3 2 1 2 3
//4 3 2 1 2 3 4
// 3 2 1 2 3
// 2 1 2
// 1
static void pattern7(int n) {
for (int row = 1; row <= 2 * n; row++) {
int c = row > n ? 2 * n - row: row;
for (int space = 0; space < n-c; space++) {
System.out.print(" ");
}
for (int col = c; col >= 1; col--) {
System.out.print(col + " ");
}
for (int col = 2; col <= c; col++) {
System.out.print(col + " ");
}
System.out.println();
}
}
}