Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java: Create a program called Average java that reads in integers from the user

ID: 3681360 • Letter: J

Question

Java:

Create a program called Average java that reads in integers from the user until they provide an input of done, at which point the program prints the average (floating point value) of the previously entered numbers, and then terminates. You can assume that the user only enters valid input. Here is an example run, in which text entered by the user is depicted in blue... this example shows exactly what the console would look like at the end of execution if the user types the blue input. Enter an integer or "done to finish: 10 Enter an integer or "done to finish: 15 Enter an integer or "done to finish: 12 Enter an integer or "done to finish: done Average of inputs is 12. 333 33 33 33 33 33 34

Explanation / Answer

/**********Average.java ***********************/

import java.util.*;
import java.util.Scanner;
import java.util.ArrayList;

public class Average {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int sum =0;
int i = 0;
while (true) {
System.out.print("Enter an Integer, or done to finish: ");
String input = scanner.nextLine();
  
if (input.equals("done")) break;
else {
int number = Integer.parseInt(input);
sum = sum + number;
i++;
}
}


System.out.println("Average of inputs: "+(double) sum/i);
  
}
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote