File tree 1 file changed +42
-0
lines changed
InterviewPrograms/src/com/java/patterns
1 file changed +42
-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 3 3
7
+ 5 5 5 5 5
8
+ 7 7 7 7 7 7 7
9
+ 9 9 9 9 9 9 9 9 9
10
+ */
11
+ public class Pattern23 {
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
+ int k = 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 <=k ;j ++)
21
+ if (j == 0 )
22
+ System .out .print (k +1 );
23
+ else
24
+ System .out .print (" " +(k +1 ));
25
+ iSpace ++;
26
+ k +=2 ;
27
+ if (i != N -1 )
28
+ System .out .println ();
29
+ }
30
+ scanner .close ();
31
+ }
32
+ }
33
+ /*
34
+ Input
35
+ 5
36
+ Output
37
+ 1
38
+ 3 3 3
39
+ 5 5 5 5 5
40
+ 7 7 7 7 7 7 7
41
+ 9 9 9 9 9 9 9 9 9
42
+ */
You can’t perform that action at this time.
0 commit comments