File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Pattern Printing
2
+
3
+ ## Pattern 1: sum.java
4
+
5
+   ;  ;  ;  ; 28<br >
6
+   ;  ;  ; 13 15<br >
7
+   ;  ; 6 7 8<br >
8
+   ; 3 3 4 4<br >
9
+ 1 2 1 3 1
Original file line number Diff line number Diff line change
1
+ class Sum {
2
+ public void print (int arr [],int n )
3
+ {
4
+ int b [] = new int [arr .length -1 ];
5
+ if (arr .length >1 )
6
+ {
7
+ for (int i =0 ;i <arr .length -1 ;i ++)
8
+ {
9
+ b [i ] = arr [i ] + arr [i +1 ];
10
+ }
11
+ print (b ,n );
12
+ }
13
+
14
+ System .out .println ();
15
+ for (int j =0 ;j <n -b .length ;j ++)
16
+ {
17
+ System .out .print (" " );
18
+ }
19
+ for (int j =0 ;j <b .length ;j ++)
20
+ {
21
+ System .out .print (b [j ]+" " );
22
+ }
23
+ }
24
+ public static void main (String args [])
25
+ {
26
+ Sum s = new Sum ();
27
+ //int a[] = {1,1,1,1,1};
28
+ int a [] = {1 ,2 ,1 ,3 ,1 };
29
+ s .print (a ,a .length );
30
+ System .out .println ();
31
+ for (int j =0 ;j <a .length ;j ++)
32
+ {
33
+ System .out .print (a [j ]+" " );
34
+ }
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments