-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathsum.java
36 lines (35 loc) · 818 Bytes
/
sum.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Sum{
public void print(int arr[],int n)
{
int b[] = new int[arr.length-1];
if(arr.length>1)
{
for(int i =0;i<arr.length-1;i++)
{
b[i] = arr[i] + arr[i+1];
}
print(b,n);
}
System.out.println();
for(int j=0;j<n-b.length;j++)
{
System.out.print(" ");
}
for(int j=0;j<b.length;j++)
{
System.out.print(b[j]+" ");
}
}
public static void main(String args[])
{
Sum s = new Sum();
//int a[] = {1,1,1,1,1};
int a[] = {1,2,1,3,1};
s.print(a,a.length);
System.out.println();
for(int j=0;j<a.length;j++)
{
System.out.print(a[j]+" ");
}
}
}