-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPattern9.java
42 lines (39 loc) · 1.01 KB
/
Pattern9.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
41
42
public class Pattern9 {
public static void main(String[] args) {
// *
// ***
// *****
// *******
// *********
// *********
// *******
// *****
// ***
// *
int row=5;
for (int i = 1; i <= row; i++) {
int first = row - i + 1;
int last = row + i - 1;
for (int j = 1; j <= (row * 2) - 1; j++) {
if (j >= first && j <= last ) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
for (int i = row; i >= 1; i--) {
int first = row - i + 1;
int last = row + i - 1;
for (int j = 1; j <= (row * 2) - 1; j++) {
if (j >= first && j <= last) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}