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
+ 1
6
+ 3 2 1
7
+ 5 4 3 2 1
8
+ 7 6 5 4 3 2 1
9
+ 9 8 7 6 5 4 3 2 1
10
+ */
11
+ public class Pattern19 {
12
+ public static void main (String args [] ) throws Exception {
13
+ Scanner scanner = new Scanner (System .in );
14
+ int N = Integer .parseInt (scanner .nextLine ());
15
+ int iSpace = 0 ;
16
+ for (int i =0 ;i <N ;i ++){
17
+ for (int j = iSpace ;j <N -1 ;j ++)
18
+ System .out .print (" " );
19
+ for (int j =2 *i +1 ;j >=1 ;j --)
20
+ if (j == 2 *i +1 )
21
+ System .out .print (j );
22
+ else
23
+ System .out .print (" " +j );
24
+ iSpace ++;
25
+ if (i != N -1 )
26
+ System .out .println ();
27
+ }
28
+ scanner .close ();
29
+ }
30
+ }
31
+ /*
32
+ Input
33
+ 5
34
+ Output
35
+ 1
36
+ 3 2 1
37
+ 5 4 3 2 1
38
+ 7 6 5 4 3 2 1
39
+ 9 8 7 6 5 4 3 2 1
40
+ */
You can’t perform that action at this time.
0 commit comments