package javaapplication9;
import java.util.Scanner;
public class JavaApplication9 {
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
int sum=0,a=0;
int []x=new int[5];
for (int i = 0; i < x.length; i++)
{
System.out.println("Enter the number at index "+i);
x[i]=obj.nextInt();
}
System.out.println("-------Printing the values--------");
for(int c:x)
{
System.out.println(c);
}
while(a<x.length)
{
sum=sum+x[a];
a++;
}
System.out.println("-------Sum of the Array--------");
System.out.println("sum = "+sum);
}
}
No comments:
Post a Comment