-
Notifications
You must be signed in to change notification settings - Fork 0
/
PatternThirteen.java
40 lines (37 loc) · 953 Bytes
/
PatternThirteen.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
34
35
36
37
38
39
40
package patterns;
/**
* Print below pattern
* 1 1
* 1 2 2 1
* 1 2 3 3 2 1
* 1 2 3 4 4 3 2 1
*/
public class PatternThirteen {
public static void main(String[] args) {
int n = 5;
printPattern(n);
}
private static void printPattern(int n) {
for (int i = 1; i <= n; i++) {
int j = 1;
while (j <= 2 * n) {
int counter = 0;
while (j <= i) {
counter++;
System.out.print(counter);
j++;
}
while (j <= 2 * n - i) {
System.out.print(" ");
j++;
}
while (j <= 2 * n) {
System.out.print(counter);
counter--;
j++;
}
}
System.out.println();
}
}
}