Skip to content

Commit c604bf0

Browse files
committed
Pattern 18
1 parent 9cee4a5 commit c604bf0

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.java.patterns;
2+
import java.util.Scanner;
3+
/*
4+
Write the program to print the following pattern
5+
A
6+
A B C
7+
A B C D E
8+
A B C D E F G
9+
A B C D E F G H I
10+
*/
11+
public class Pattern18 {
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+
for(int i=0;i<N;i++){
18+
for(int j = iSpace;j<N-1;j++)
19+
System.out.print(" ");
20+
for(int j=0;j<(2*i+1);j++)
21+
if(j == 0)
22+
System.out.print(s.charAt(j));
23+
else
24+
System.out.print(" "+s.charAt(j));
25+
iSpace++;
26+
if(i != N-1)
27+
System.out.println();
28+
}
29+
scanner.close();
30+
}
31+
}
32+
/*
33+
Input
34+
5
35+
Output
36+
A
37+
A B C
38+
A B C D E
39+
A B C D E F G
40+
A B C D E F G H I
41+
*/

0 commit comments

Comments
 (0)