-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathnumericpattern122.java
More file actions
46 lines (41 loc) · 977 Bytes
/
numericpattern122.java
File metadata and controls
46 lines (41 loc) · 977 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
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
*
* pattern to be printed
*
* 3
* 2 3
* 1 2 3
* 0 1 2 3
* 1 2 3
* 2 3
* 3
*
* numericpattern122
*/
class numericpattern122 {
public static void main(String[] args) {
int rows = 7;
numericPattern122(rows);
}
private static void numericPattern122(int n) {
n/=2;
for (int i = 0; i <= n; i++) {
for (int j = 1; j <=n-i; j++) {
System.out.print(" ");
}
for (int j = 0; j <= i; j++) {
System.out.print((n-i+j)+" ");
}
System.out.println();
}
for (int i = 0; i <= n; i++) {
for (int j = -1; j <i; j++) {
System.out.print(" ");
}
for (int j = 0; j < n-i; j++) {
System.out.print((j+i+1)+" ");
}
System.out.println();
}
}
}