-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStarPattern.java
More file actions
35 lines (31 loc) · 969 Bytes
/
Copy pathStarPattern.java
File metadata and controls
35 lines (31 loc) · 969 Bytes
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 StarPattern {
public static void main(String[] args) {
int rows = 5;
System.out.println("Pyramid Pattern:");
printPyramid(rows);
System.out.println("\nInverted Pyramid Pattern:");
printInvertedPyramid(rows);
}
static void printPyramid(int rows) {
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= rows - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= (2 * i - 1); k++) {
System.out.print("*");
}
System.out.println();
}
}
static void printInvertedPyramid(int rows) {
for (int i = rows; i >= 1; i--) {
for (int j = 1; j <= rows - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= (2 * i - 1); k++) {
System.out.print("*");
}
System.out.println();
}
}
}