-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern.java
More file actions
118 lines (105 loc) · 3 KB
/
Copy pathPattern.java
File metadata and controls
118 lines (105 loc) · 3 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
public class Pattern {
void P1() {
System.out.println("Pattern P1");
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
System.out.print(" * ");
}
System.out.println(" ");
}
}
void P2() {
System.out.println("Pattern P2");
for (int R = 1; R <= 5; R++) {
for (int C = 1; C <= R; C++) {
System.out.print("*");
}
System.out.println(" ");
}
}
void P3() {
System.out.println("Pattern P3");
for (int R = 5; R >= 1; R--) {
for (int C = 1; C <= R; C++) {
System.out.print(C);
}
System.out.println(" ");
}
}
void P4() {
System.out.println("Pattern P4");
for (int R = 1; R <= 5; R++) {
for (int C = 1; C <= 5; C++) {
if (R >= 2 && C >= 2 && R <= 4 && C <= 4) {
System.out.print(" ");
} else {
System.out.print(" * ");
}
}
System.out.println();
}
}
void P5() {
System.out.println("Pattern P5");
for (int R = 1; R <= 5; R++) {
for (int C = 1; C < 5; C++) {
System.out.print(" ");
}
for (int C = R; C < 5; C++) {
System.out.print(" * ");
}
System.out.println();
}
}
void P6() {
System.out.println("Pattern P6");
for (int R = 1; R <= 5; R++) {
for (int C = 1; C <= 5; C++) {
if ((R >= 2 && C >= 2 && R <= 4 && C <= 4) || (R == 1 && C == 1) || (R == 1 && C == 5)
|| (R == 5 && C == 1) || (R == 5 && C == 5)) {
System.out.print(" ");
} else {
System.out.print(" * ");
}
}
System.out.println();
}
}
void P7() {
System.out.println("Pattern P7");
for (int R = 1; R <= 5; R++) {
for (int C = 1; C <= 5; C++) {
if ((C == 1 || C == 5 || R == C)) {
System.out.print(" N ");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
void P8() {
System.out.println("Pattern P8");
for (int R = 1; R <= 5; R++) {
for (int C = 1; C <= 5; C++) {
if (R == 1 || R == 3 || R == 5 || (R == 2 && C == 1) || (R == 4 && C == 5)) {
System.out.print(" S ");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
public static void main(String Args[]) {
Pattern obj = new Pattern();
obj.P1();
obj.P2();
obj.P3();
obj.P4();
obj.P5();
obj.P6();
obj.P7();
obj.P8();
}
}