File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
InterviewPrograms/src/com/java/patterns Expand file tree Collapse file tree 1 file changed +40
-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 B C D E
6+ A B C D
7+ A B C
8+ A B
9+ A
10+ */
11+ public class Pattern26 {
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+ for (int i =0 ;i <N ;i ++){
17+ for (int j = 0 ;j <i ;j ++)
18+ System .out .print (" " );
19+ for (int j =0 ;j <N -i ;j ++)
20+ if (j == 0 )
21+ System .out .print (s .charAt (j ));
22+ else
23+ System .out .print (" " +s .charAt (j ));
24+ if (i != N -1 )
25+ System .out .println ();
26+ }
27+ scanner .close ();
28+ }
29+ }
30+
31+ /*
32+ Input
33+ 5
34+ Output
35+ A B C D E
36+ A B C D
37+ A B C
38+ A B
39+ A
40+ */
You can’t perform that action at this time.
0 commit comments