-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pattern1.java
47 lines (46 loc) · 1.06 KB
/
Pattern1.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
37
38
39
40
41
42
43
44
45
46
47
import java.util.Scanner;
public class Pattern1
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n,l,i,k=0,c=0,x,j;
System.out.println("Enter the number of inputs:");
n=sc.nextInt();
x=n;
l=(n*(n+1))/2;
int arr[]=new int[l];
System.out.println("Enter the numbers:");
for(i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
for(i=n;i<l;i++)
{
for(j=x-1;j>0;j--)
{
arr[n]=arr[k]+arr[k+j];
n++;
if(j==l)
{
k=k+2;
}
else
{
k++;
}
}
x--;
}
k=0;
for(i=5;i>=l;i--)
{
for(j=1;j<=i;j++)
{
System.out.println(arr[k]+" ");
k++;
}
System.out.println();
}
}
}