-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeftPyramid
44 lines (43 loc) · 1018 Bytes
/
LeftPyramid
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
class LeftPyramid{
//Using Stack Builder
public static void printstar(int star) {
//Termination case
if(star==0){
return;
}
//Business logic
System.out.print("*");
//Recursive call
printstar(star-1);
}
public static void printline(int row,int index) {
//Termination case
if(row==0){
return;
}
//Business logic
printstar(index);
System.out.println();
//Recursive call
printline(row-1,index+1);
}
//Using Stack Falling
public static int printline(int row) {
//Termination case
if(row==0){
return row;
}
//Recursive call
printstar(printline(row-1));
//Business logic
if(row==5){
System.out.println();
printstar(5);
}
System.out.println();
return row;
}
public static void main(String[] args) {
printline(5);
}
}