Question #263176

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


Expert's answer

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);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS