Answer to Question #287458 in Java | JSP | JSF for Timo

Question #287458

Write a java application that calculates and prints sum and average of any 30 numbers .Use a do while statement to loop through the calculation

1
Expert's answer
2022-01-14T13:46:06-0500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int count = 30;
        double sum = 0;
        do {
            sum += in.nextInt();
        } while (--count > 0);
        System.out.println("Sum: " + sum);
        System.out.println("Average: " + sum / 30);
    }
}

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