Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2f47d2b

Browse files
⭐Added Inverted Half Pyramid Pattern
1 parent 6175465 commit 2f47d2b

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed
338 Bytes
Binary file not shown.

‎src/PyramidPatterns.java‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
public class PyramidPatterns {
22
public static void main(String[] args) {
3+
int length = 6;
34

45
System.out.println("""
5-
+--------------+
6-
| Half Pyramid |
7-
+--------------+
8-
""");
9-
halfPyramid(5);
6+
+----------------------+
7+
| Half Pyramid |
8+
+----------------------+""");
9+
halfPyramid(length);
10+
11+
System.out.println("""
12+
+-----------------------+
13+
| Inverted Half Pyramid |
14+
+-----------------------+""");
15+
invertedHalfPyramid(length);
1016

1117
}
1218

@@ -17,4 +23,12 @@ public static void halfPyramid(int length) {
1723
System.out.println();
1824
}
1925
}
26+
27+
public static void invertedHalfPyramid(int length) {
28+
for(int i=length; i>=1; i--){
29+
for (int j=1; j<=i; j++)
30+
System.out.print("* ");
31+
System.out.println();
32+
}
33+
}
2034
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /