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