File tree 1 file changed +51
-0
lines changed
Filter options
1 file changed +51
-0
lines changed
Original file line number Diff line number Diff line change
1
+ package Pattern .NumberPattern ;
2
+
3
+ public class NumericDiamondPattern {
4
+ public static void main (String [] args ) {
5
+ int n = 4 , count = 0 ;
6
+ for (int i = 1 ; i <= n ; i ++) {
7
+ for (int j = i ; j < n ; j ++) {
8
+ System .out .print (" " );
9
+ }
10
+
11
+ count +=i ;
12
+ for (int j = 1 ; j <= i ; j ++) {
13
+
14
+ System .out .print (count +" " );
15
+ if (j <i ) count --; else count +=i -1 ;
16
+ }
17
+ System .out .println ();
18
+ }
19
+
20
+ for (int i = 1 ; i <= n ; i ++) {
21
+ for (int j = 1 ; j < i ; j ++) {
22
+ System .out .print (" " );
23
+ }
24
+
25
+ for (int j = i ; j <= n ; j ++) {
26
+ System .out .print (count +" " );
27
+ count --;
28
+ }
29
+
30
+ System .out .println ();
31
+ }
32
+ }
33
+ }
34
+
35
+ // Input:
36
+ // n = 4
37
+
38
+ // Output:
39
+ // 1
40
+ // 3 2
41
+ // 6 5 4
42
+ // 10 9 8 7
43
+ // 10 9 8 7
44
+ // 6 5 4
45
+ // 3 2
46
+ // 1
47
+
48
+ // Explaination:
49
+ // First upperTriangle like reverse number printing
50
+ // Add the row value to count value minus each columns when last column is reached then
51
+ // add current count with row value - 1 (to reach the initial value)
You can’t perform that action at this time.
0 commit comments