Answer to Question #263176 in Java | JSP | JSF for Marwa

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


1
Expert's answer
2021-11-09T10:20:54-0500
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS