-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern19.java
More file actions
39 lines (37 loc) · 1.19 KB
/
Pattern19.java
File metadata and controls
39 lines (37 loc) · 1.19 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
public class Pattern19 {
public Pattern19(int n){
for (int row = 0; row < n-1; row++) {
for (int col = row+1; col < n; col++) {
System.out.print(" ");
}
for (int col = 2*row; col >= 0; col--) {
if(col==row||col>=2*row){
System.out.print("* ");
}
else{
System.out.print(" ");
}
}
System.out.println();
}
for (int row = 1; row <= n; row++) {
int c = row > n ? 2*n-row:row;
for (int col = 1; col < c; col++) {
System.out.print(" ");
}
for (int col = n; col >= c; col--) {
if (col>=n||col<row+1) {
System.out.print("* ");
}
else if (row>=n) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
System.out.println();
}
}