-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathf_pattern3.java
More file actions
35 lines (31 loc) · 859 Bytes
/
Copy pathf_pattern3.java
File metadata and controls
35 lines (31 loc) · 859 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
public class f_pattern3 {
static void printSpace(int noOfSpaces) {
if(noOfSpaces == 0) {
return;
}
System.out.print(" ");
printSpace(noOfSpaces-1);
}
static void printStar(int noOfStar) {
// Base Case
if(noOfStar == 0) {
return;
}
// Processing Logic
System.out.print("* ");
// Small Problem
printStar(noOfStar - 1);
}
static void printPattern(int rows, int currentRow) {
if(rows == 0) {
return;
}
printSpace(rows-1);
printStar(currentRow); // print the row
System.out.println(); // move to the new line
printPattern(rows-1, currentRow+1);
}
public static void main(String[] args) {
printPattern(5, 1);
}
}