Skip to content

Commit 095a677

Browse files
Recursion Day 5 is completed
1 parent f692ae6 commit 095a677

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package Recursion;
2+
3+
public class PatternRightAngleTriangle {
4+
5+
static void downPattern(int row,int col) {
6+
if(row==-1)
7+
return;
8+
if(row == col){
9+
System.out.println();
10+
downPattern(row-1, 0);
11+
}
12+
else{
13+
System.out.print("* ");
14+
downPattern(row,col+1);
15+
}
16+
}
17+
static void upPattern(int row,int col) {
18+
if(row==-1)
19+
return;
20+
if(row == col){
21+
upPattern(row-1, 0);
22+
System.out.println();
23+
}
24+
else{
25+
upPattern(row,col+1);
26+
System.out.print("* ");
27+
}
28+
}
29+
public static void main(String[] args) {
30+
downPattern(4,0);
31+
upPattern(4, 0);
32+
}
33+
}
34+
35+
36+
//output
37+
// * * * *
38+
// * * *
39+
// * *
40+
// *
41+
42+
43+
44+
// *
45+
// * *
46+
// * * *
47+
// * * * *

0 commit comments

Comments
 (0)