Welcome to ICSE Java Answers. Ask any questions you have related to Java and we will answer them.
Java is a registered trademark of Oracle. This site is in no way related to or endorsed by Oracle.

write a pattern program to take n number of values and print sum

0 votes

1   3   2   4   5

4   5   6   9

9   11 15

20  26

46

asked by dipesh (83 points)

1 Answer

+1 vote
import java.util.*;
public class pattern
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        int n;
        System.out.println("Enter number of inputs:");
        n=sc.nextInt();
        int arr[]=new int[n];
        
        System.out.println("Enter "+n+" elements:");        
        for(int i=0;i<n;i++)
        {
            arr[i]=sc.nextInt();
        }
        
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n-i;j++)
            {
                if(i!=0)
                {
                    arr[j]=(arr[j]+arr[j+1]);
                }
                System.out.print(arr[j]+" ");
            }
            System.out.println();
        } 
    }
}
answered by Anonymous_1 (85 points)
thanks for helping me
...