forked from PrajaktaSathe/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern9.java
More file actions
28 lines (26 loc) · 713 Bytes
/
Pattern9.java
File metadata and controls
28 lines (26 loc) · 713 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
package Programs.patterns;
public class Pattern9 {
public static void main(String[] args) {
pattern9(4);
}
// 4 4 4 4 4 4 4 4 4
// 4 3 3 3 3 3 3 3 4
// 4 3 2 2 2 2 2 3 4
// 4 3 2 1 1 1 2 3 4
// 4 3 2 1 0 1 2 3 4
// 4 3 2 1 1 1 2 3 4
// 4 3 2 2 2 2 2 3 4
// 4 3 3 3 3 3 3 3 4
// 4 4 4 4 4 4 4 4 4
static void pattern9(int n) {
int originalN = n;
n = 2 * n;
for (int row = 0; row <= n; row++) {
for (int col = 0; col <= n; col++) {
int atEveryIndex = originalN - Math.min(Math.min(row, col), Math.min(n - row, n - col));
System.out.print(atEveryIndex + " ");
}
System.out.println();
}
}
}