Repository navigation
Expand file tree
/
Copy pathpat24.java
More file actions
43 lines (43 loc) · 1.47 KB
/
Copy pathpat24.java
File metadata and controls
43 lines (43 loc) · 1.47 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
public class pat24 {
public static void main(String[] args) {
int n =5;
for (int row = 1; row <= 2*n-1; row++) {
if(row<=n){
for (int col = 1; col <= row; col++) {
if(col==1 || col==row)
System.out.print("*");
else
System.out.print(" ");
}
for (int col = 1; col <=2*(n-row+1)-2; col++) {
System.out.print(" ");
}
for (int col = 1; col <= row; col++) {
if(col==1 || col==row)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
if(row>n){
for (int col = 1; col <= 2*n-row; col++) {
if(col==1 || col==2*n-row)
System.out.print("*");
else
System.out.print(" ");
}
for (int col = 1; col <= 2*(row-n) ; col++) {
System.out.print(" ");
}
for (int col = 1; col <= 2*n-row; col++) {
if(col==1 || col==2*n-row)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
}