Skip to content

Commit 9cee4a5

Browse files
committed
Pattern 17
1 parent 8753eab commit 9cee4a5

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+
C B A
7+
E D C B A
8+
G F E D C B A
9+
I H G F E D C B A
10+
*/
11+
public class Pattern17 {
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=2*i;j>=0;j--)
21+
if(j == 2*i)
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+
C B A
38+
E D C B A
39+
G F E D C B A
40+
I H G F E D C B A
41+
*/

0 commit comments

Comments
 (0)