-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy path2.java
More file actions
51 lines (40 loc) · 882 Bytes
/
2.java
File metadata and controls
51 lines (40 loc) · 882 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Java program to Print Reverse Pyramid Star Pattern
// Using While loop
// Importing input output classes
import java.io.*;
// Main class
class GFG {
// Main driver method
public static void main(String[] args)
{
// Declaring and initializing variable to
// Size of the pyramid
int number = 7;
int i = number, j;
// Nested while loops
// Outer loop
// Till condition holds true
while (i > 0) {
j = 0;
// Inner loop
// Condition check
while (j++ < number - i) {
// Print whitespaces
System.out.print(" ");
}
j = 0;
// Inner loop
// Condition check
while (j++ < (i * 2) - 1) {
// Print star
System.out.print("*");
}
// By now, we reach end of execution for one row
// so next line
System.out.println();
// Decrementing counter because we want to print
// reverse of pyramid
i--;
}
}
}