Skip to content

Commit 0d1bd88

Browse files
committed
Done some advanced pattern question
1 parent cccd3e1 commit 0d1bd88

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

12_Patterns/AdvancePattern.class

1.5 KB
Binary file not shown.

12_Patterns/AdvancePattern.java

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static void main(String[] args) {
7070
}
7171
System.out.println();
7272
}
73-
System.out.println("---------------------------- Pattern4 ----------------------------");
73+
System.out.println("---------------------------- Pattern5 ----------------------------");
7474
// 1
7575
// 23
7676
// 345
@@ -84,5 +84,72 @@ public static void main(String[] args) {
8484
System.out.println();
8585
}
8686

87+
System.out.println("---------------------------- Pattern6 ----------------------------");
88+
// 1
89+
// 23
90+
// 345
91+
// 4567
92+
String pattern[] = new String[n];
93+
for (int i = 0; i < n; i++) {
94+
StringBuilder row = new StringBuilder();
95+
int num = i + 1;
96+
for (int j = 0; j <= i; j++) {
97+
row.append(num);
98+
num++;
99+
}
100+
pattern[i] = row.toString();
101+
}
102+
for (String row : pattern) {
103+
System.out.println(row);
104+
}
105+
106+
for (int i = 0; i < n; i++) {
107+
int num = i + 1;
108+
109+
for (int j = 0; j < i; j++) {
110+
System.out.print(" ");
111+
}
112+
for (int j = n; j > i; j--) {
113+
System.out.print(num + " ");
114+
num++;
115+
}
116+
System.out.println();
117+
118+
}
119+
for (int i = 1; i <= n - 1; i++) {
120+
int num = n - i;
121+
for (int j = n - 1; j > i; j--) {
122+
System.out.print(" ");
123+
}
124+
for (int j = 0; j <= i; j++) {
125+
System.out.print(num + " ");
126+
num++;
127+
}
128+
System.out.println();
129+
130+
}
131+
for (int i = 0; i < n; i++) {
132+
for (int j = 0; j < i; j++) {
133+
System.out.print(" ");
134+
}
135+
for (int j = 0; j < n - i; j++) {
136+
System.out.print("*");
137+
}
138+
System.out.println();
139+
}
140+
for (int i = 1; i < 2 * n; i++) {
141+
int count = i;
142+
if (i > n)
143+
count = 2 * n - i;
144+
for (int j = 0; j < count-1; j++) {
145+
System.out.print(" ");
146+
}
147+
for (int j = 1; j <= i; j++) {
148+
if (j == i) {
149+
System.out.print(count);
150+
}
151+
}
152+
System.out.println();
153+
}
87154
}
88155
}

12_Patterns/AdvancedPattern2.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package 12_Patterns;
2+
3+
public class AdvancedPattern2 {
4+
5+
}

0 commit comments

Comments
 (0)