File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Print the following pattern for the given number of rows.
3
+ Pattern for N = 4
4
+
5
+ 1
6
+ 232
7
+ 34543
8
+ 4567654
9
+ */
10
+
11
+ import java .util .*;
12
+
13
+ public class Triangle_of_Numbers {
14
+ public static void main (String [] args ) {
15
+
16
+ /*
17
+ * Your class should be named Solution.
18
+ * Read input as specified in the question.
19
+ * Print output as specified in the question.
20
+ */
21
+ Scanner sc = new Scanner (System .in );
22
+ int n = sc .nextInt ();
23
+ int i , j , num = 1 , gap ;
24
+
25
+ gap = n - 1 ;
26
+
27
+ for (j = 1 ; j <= n ; j ++) {
28
+ num = j ;
29
+
30
+ for (i = 1 ; i <= gap ; i ++)
31
+ System .out .print (" " );
32
+
33
+ gap --;
34
+
35
+ for (i = 1 ; i <= j ; i ++) {
36
+ System .out .print (num );
37
+ num ++;
38
+ }
39
+ num --;
40
+ num --;
41
+ for (i = 1 ; i < j ; i ++) {
42
+ System .out .print (num );
43
+ num --;
44
+ }
45
+ System .out .println ();
46
+ }
47
+
48
+ }
49
+
50
+ }
You can’t perform that action at this time.
0 commit comments