-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern.java
More file actions
33 lines (31 loc) · 741 Bytes
/
Copy pathPattern.java
File metadata and controls
33 lines (31 loc) · 741 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
package Recursion;
public class Pattern {
public static void main(String[] args) {
triangle(4,0);
triangle2(4,0);
}
static void triangle (int r, int c){
if (r==0){
return;
}
if (c<r){
System.out.print(" * ");
triangle(r, c+1);
}else {
System.out.println();
triangle(r-1, 0);
}
}
static void triangle2 (int r, int c){
if (r==0){
return;
}
if (c<r){
triangle2(r, c+1);
System.out.print(" * "); // prints only when they are removing from stack.
}else {
triangle2(r-1, 0);
System.out.println();
}
}
}