Skip to content

Commit 5a5d366

Browse files
committed
Pattern 22 - Techgig
1 parent 475fb8f commit 5a5d366

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.java.patterns;
2+
import java.util.Scanner;
3+
/*
4+
Write the program to print the following pattern
5+
A
6+
B B B
7+
C C C C C
8+
D D D D D D D
9+
E E E E E E E E E
10+
*/
11+
public class Pattern22 {
12+
public static void main(String args[] ) throws Exception {
13+
Scanner scanner = new Scanner(System.in);
14+
int N = Integer.parseInt(scanner.nextLine());
15+
String s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
16+
int iSpace = 0;
17+
int k = 0;
18+
for(int i=0;i<N;i++){
19+
for(int j = iSpace;j<N-1;j++)
20+
System.out.print(" ");
21+
for(int j=0;j<=k;j++)
22+
if(j == 0)
23+
System.out.print(s.charAt(i));
24+
else
25+
System.out.print(" "+s.charAt(i));
26+
iSpace++;
27+
k+=2;
28+
if(i != N-1)
29+
System.out.println();
30+
}
31+
scanner.close();
32+
}
33+
}
34+
/*
35+
Input
36+
5
37+
Output
38+
A
39+
B B B
40+
C C C C C
41+
D D D D D D D
42+
E E E E E E E E E
43+
*/

0 commit comments

Comments
 (0)