-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathnumericpattern123.java
More file actions
49 lines (43 loc) · 1.01 KB
/
numericpattern123.java
File metadata and controls
49 lines (43 loc) · 1.01 KB
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
49
/**
*
* pattern to be printed
*
* 1
* 2 2
* 3 3 3
* 4 4 4 4
* 5 5 5
* 6 6
* 7
* numericpattern123
*/
class numericpattern123 {
public static void main(String[] args) {
int rows = 7;
numericPattern123(rows);
}
private static void numericPattern123(int n) {
int c=1;
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((c)+" ");
}
c++;
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((c)+" ");
}
c++;
System.out.println();
}
}
}