forked from Itachi-Ucchiha/BasicDSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17thJune(III).java
More file actions
85 lines (71 loc) · 1.63 KB
/
Copy path17thJune(III).java
File metadata and controls
85 lines (71 loc) · 1.63 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
public class Pattern1 {
// printing the stars
static void printStar(int numberOfStar){
if(numberOfStar==0){
return;
}
System.out.print("* ");
numberOfStar-=1;
printStar(numberOfStar);
}
// printing the whitespaces
static void printSpace(int numberOfSpace){
if(numberOfSpace==0){
return;
}
System.out.print(" ");
numberOfSpace-=1;
printSpace(numberOfSpace);
}
//----------------------------------------------------------------------------------------
// pattern 1
static void printPattern1(int row, int currentRow){
if(row == 0){
return;
}
printStar(currentRow);
System.out.println();
printPattern1(row-1, currentRow+1);
}
// pattern 2
static void printPattern2(int row, int currentRow){
if(row == 0){
return;
}
printStar(row);
System.out.println();
printPattern2(row-1, currentRow+1);
}
//pattern 3
static void printPattern3(int row, int currentRow){
if(row==0){
return;
}
printSpace(row-1);
printStar(currentRow);
System.out.println();
printPattern3(row-1, currentRow+1);
}
public static void main(String[] args) {
printPattern1(5,1);
System.out.println();
printPattern2(5,1);
System.out.println();
printPattern3(5, 1);
}
}
// OP ===
// *
// * *
// * * *
// * * * *
// * * * * *
// * * * * *
// * * * *
// * * *
// * *
// *
// *
// * *
// * * *
// * * * *