-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrintPyramidStars.java
More file actions
55 lines (46 loc) · 1.18 KB
/
PrintPyramidStars.java
File metadata and controls
55 lines (46 loc) · 1.18 KB
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
52
53
54
55
public class PrintPyramidStars {
public static void main(String[] args) {
System.out.println("Lets print Pyramid of stars");
System.out.println("Enter the number of rows");
Scanner sc1=new Scanner(System.in);
int rows=sc1.nextInt();
pyramidStars(rows);
System.out.println("Reverse pyramid for the same");
reversePyramidStars(rows);
}
public static void pyramidStars(int rows){
for(int row=1;row<=rows;row++){
for(int colspace=(rows-row);colspace>=1;colspace--){
System.out.print(" ");
}
for(int colstar=1;colstar<=((row*2)-1);colstar++){
System.out.print("*");
}
System.out.println("");
}
}
public static void reversePyramidStars(int rows){
for(int row=rows;row>=1;row--){
for(int colspace=(rows-row);colspace>=1;colspace--){
System.out.print(" ");
}
for(int colstar=((row*2)-1);colstar>=1;colstar--){
System.out.print("*");
}
System.out.println("");
}
}
Output:
*
***
*****
*******
*********
Reverse pyramid for the same
*********
*******
*****
***
*
Combination of both codes leads to Rhombus(Note: Reduce the total number of rows by 1 in the
first loop of reverse pyramid i.e row=rows-1)