Java Program to print sum of Array|EasyCoding45

In This Tutorial we are going to learn how we can write a Java Program to print sum of Elements of an Array.


Program :-


import java.util.*;

class sum

{

public static void main(String s[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter Limit for Array :");

int n=sc.nextInt();

int arr[]=new int[n];

int sum=0;

System.out.println("Enter Elements in an Array :");

for(int i=0;i<n;i++)

{

 

int elmt=sc.nextInt();

arr[i]=elmt;

sum=sum+arr[i];

}

System.out.println("Sum of Elements of an Array is :"+sum);

}

}


Output :-





                                                    Thank You💚

Comments