Answer to Question #285075 in Java | JSP | JSF for Jericho

Question #285075

Write a Java program that ask the user of the number of elements in array and input

elements as much as the number of elements. Print the inputted elements and determine the

sum and average of the array. (You must input 10 elements and varying 3-digit numbers).


1
Expert's answer
2022-01-06T02:01:23-0500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Array size: ");
        int[] array = new int[in.nextInt()];
        double sum = 0;
        for (int i = 0; i < array.length; i++) {
            array[i] = in.nextInt();
            sum += array[i];
        }
        for (int element : array) {
            System.out.println(element);

        }
        System.out.println("Sum: " + sum);
        System.out.println("Average: " + sum / array.length);
    }
}

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