-
Notifications
You must be signed in to change notification settings - Fork 61
/
Pattern15.java
45 lines (45 loc) · 1.08 KB
/
Pattern15.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.java.patterns;
import java.util.Scanner;
/*
Write the program to print the following pattern
A
B A B
C B A B C
D C B A B C D
E D C B A B C D E
*/
public class Pattern15 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = Integer.parseInt(scanner.nextLine().trim());
String CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int d = (N-1)*2;
for(int i=0;i<N;i++){
for(int j=0;j<d-1;j++)
System.out.print(" ");
for(int j=i;j>=0;j--)
if(i == N-1 && j == i)
System.out.print(CHARS.charAt(j));
else
System.out.print(" "+CHARS.charAt(j));
for(int j=1;j<=i;j++)
System.out.print(" "+CHARS.charAt(j));
if(i==0 && N != 1)
System.out.print(" ");
d-=2;
if(i < N-1)
System.out.println();
}
scanner.close();
}
}
/*
Input
5
Output
A
B A B
C B A B C
D C B A B C D
E D C B A B C D E
*/