We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
import java.util.*;
class Solution
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
int s=0,n;
System.out.println("enter the number of terms you want to have in the integer array");
n=sc.nextInt();
int ar[]=new int[n];
System.out.println("enter the array elements");
for(i=0;i<=n;i++)
{
ar[i]=sc.nextInt();
s=s+ar[i];
}
System.out.println("sum of array"+s);
Simple Array Sum
You are viewing a single comment's thread. Return to all comments →
import java.util.*; class Solution { public static void main(String[]args) { Scanner sc=new Scanner(System.in); int s=0,n; System.out.println("enter the number of terms you want to have in the integer array"); n=sc.nextInt(); int ar[]=new int[n]; System.out.println("enter the array elements"); for(i=0;i<=n;i++) { ar[i]=sc.nextInt(); s=s+ar[i]; } System.out.println("sum of array"+s);
} /i guess this will work/