-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStarPattern51.java
35 lines (29 loc) · 1.07 KB
/
StarPattern51.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
public class StarPattern51 {
public static void main(String[] args) {
int n = 6; // Set the number of rows
// Loop to iterate over rows
for (int i = 1; i <= n; i++) {
// Loop to print spaces before the '*'
for (int j = n; j > i; j--) {
System.out.print(" ");
}
// Loop to print '*' in each column
for (int k = 1; k <= i; k++) {
System.out.print("* ");
}
System.out.println(); // Move to the next line after each row
}
// Loop to iterate over rows in reverse order
for (int i = n - 1; i >= 1; i--) {
// Loop to print spaces before the '*'
for (int j = n - 1; j >= i; j--) {
System.out.print(" ");
}
// Loop to print '*' in each column
for (int k = 1; k <= i; k++) {
System.out.print("* ");
}
System.out.println(); // Move to the next line after each row
}
}
}