File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
InterviewPrograms/src/com/java/patterns Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
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
+ */
You can’t perform that action at this time.
0 commit comments