SUM OF ARRAY ELEMENTS 1 TO 5 IN JAVA BY TAKING INPUT FROM USER ?
INPUT:-
import java.util.Scanner;
public class example{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n[]= new int[5];
int i;
System.out.println("Enter your elements : ");
int sum=0;
for(i=0;i<5;i++){
n[i]=sc.nextInt();
}
for(i=0;i<5;i++){
System.out.println("Your number is : " + n[i]);
sum=n[i]+sum;
}
System.out.println("Your sum is = " + sum);
}
}
0 Comments