Skip to content

Commit 5a3b4af

Browse files
committed
more patterns added
1 parent 8b1d837 commit 5a3b4af

File tree

2 files changed

+139
-2
lines changed

2 files changed

+139
-2
lines changed

02_Pattern Questions/Merged_Patterns/Pattern1.java

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class Pattern1 {
44
public static void main(String[] args) {
5-
pattern2(5);
5+
pattern5(5);
66
}
77

88
// pattern Output
@@ -35,7 +35,7 @@ static void pattern1(int n) {
3535
}
3636

3737
// method 2
38-
static void pattern2(int n) {
38+
static void pattern1_1(int n) {
3939
for (int i = 0; i < 2 * n + 1; i++) {
4040
int colInRow = (i > n) ? 2 * n - i : i;
4141
for (int j = 0; j <= colInRow; j++) {
@@ -44,4 +44,103 @@ static void pattern2(int n) {
4444
System.out.println();
4545
}
4646
}
47+
48+
static void pattern2(int n){
49+
for (int i = 0; i < n*2+1; i++) {
50+
int colInRow = (i > n) ? 2 * n - i : i;
51+
for (int j = colInRow; j < n; j++) {
52+
System.out.print(" ");
53+
}
54+
for (int j = 0; j <= colInRow; j++) {
55+
System.out.print("*");
56+
}
57+
System.out.println();
58+
}
59+
}
60+
// pattern Output
61+
// *
62+
// **
63+
// ***
64+
// ****
65+
// *****
66+
// ******
67+
// *****
68+
// ****
69+
// ***
70+
// **
71+
// *
72+
static void pattern3(int n){
73+
for (int i = 0; i < n*2+1; i++) {
74+
int colInRow = (i > n) ? 2 * n - i : i;
75+
for (int j = colInRow; j < n; j++) {
76+
System.out.print(" ");
77+
}
78+
for (int j = 0; j <= colInRow; j++) {
79+
System.out.print("* ");
80+
}
81+
System.out.println();
82+
}
83+
}
84+
// Pattern output
85+
// *
86+
// * *
87+
// * * *
88+
// * * * *
89+
// * * * * *
90+
// * * * * * *
91+
// * * * * *
92+
// * * * *
93+
// * * *
94+
// * *
95+
// *
96+
97+
static void pattern4(int n){
98+
for (int i = 0; i < n*2+1; i++) {
99+
int colInRow = (i > n) ? 2 * n - i : i;
100+
for (int j = 0; j <= colInRow; j++) {
101+
System.out.print('*');
102+
}
103+
for (int j = colInRow; j < n; j++) {
104+
System.out.print(" ");
105+
}
106+
for (int j = colInRow; j < n; j++) {
107+
System.out.print(" ");
108+
}
109+
for (int j = 0; j <= colInRow; j++) {
110+
System.out.print("*");
111+
}
112+
System.out.println();
113+
}
114+
}
115+
// pattern output
116+
// * *
117+
// ** **
118+
// *** ***
119+
// **** ****
120+
// ***** *****
121+
// ************
122+
// ***** *****
123+
// **** ****
124+
// *** ***
125+
// ** **
126+
// * *
127+
128+
static void pattern5(int n){
129+
for (int i = 0; i < n*2+1; i++) {
130+
int colInRow = (i > n) ? 2 * n - i : i;
131+
for (int j = colInRow; j <= n; j++) {
132+
System.out.print("*");
133+
}
134+
for (int j = 0; j < colInRow; j++) {
135+
System.out.print(" ");
136+
}
137+
for (int j = 0; j < colInRow; j++) {
138+
System.out.print(" ");
139+
}
140+
for (int j = colInRow; j <= n; j++) {
141+
System.out.print("*");
142+
}
143+
System.out.println();
144+
}
145+
}
47146
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package Pattern_with_Alphabets;
2+
3+
public class Pattern {
4+
public static void main(String[] args) {
5+
// System.out.println();
6+
pattern2(5);
7+
}
8+
9+
static void pattern1(int n) {
10+
for (int i = 0; i < n; i++) {
11+
for (int j = 0; j <= i; j++) {
12+
System.out.print((char) ('A' + n - i + j - 1) + " ");
13+
}
14+
System.out.println();
15+
}
16+
}
17+
// pattern1 output
18+
// E
19+
// D E
20+
// C D E
21+
// B C D E
22+
// A B C D E
23+
24+
static void pattern2(int n) {
25+
for (int i = 0; i < n; i++) {
26+
for (int j = i; j < n; j++) {
27+
System.out.print((char) ('A' + n - j - 1) + " ");
28+
}
29+
System.out.println();
30+
}
31+
}
32+
// pattern output
33+
// E D C B A
34+
// D C B A
35+
// C B A
36+
// B A
37+
// A
38+
}

0 commit comments

Comments
 (0)