Write a java program that creates an array of 10 elements size. Your program should prompt the user to input numbers in array and then display the sum of all array elements
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] array = new int[10];
int total = 0;
System.out.println("Enter 10 numbers:");
for (int i = 0; i < array.length; i++) {
array[i] = in.nextInt();
total += array[i];
}
System.out.println("Total: " + total);
}
}
Comments
Leave a comment