How to sum of 5 values of an array and values entered by user

//How to sum of 5 values of an array and values entered by user.


import java.util.*;

class M
{
public static void main(String args[])
{
int a[]=new int[5];
int sum=0;
System.out.println("Enter the 5 values of an array:");
Scanner sc=new Scanner(System.in);
for(int i=0;i<5;i++)
{
a[i]=sc.nextInt();
sum=sum+a[i];
}

System.out.println("Sum="+sum);


}
}


OUTPUT:
Enter the 5 values of an array:
45
45
56
100
44
Sum=290

No comments:

Post a Comment