Answered step by step
Verified Expert Solution
Question
1 Approved Answer
specs ComputeAverage A ComputeAverage Write a class called ComputeAverage what it does: asks the user to enter three double numbers (see examples below), it
specs ComputeAverage A ComputeAverage Write a class called ComputeAverage what it does: asks the user to enter three double numbers (see examples below), it uses Scanner class to read from standard input each one of the doubles entered by the user. it then prints the average of the three numbers. Suggested steps: 1. prompt the user to enter each of the three doubles by printing. 2. read each of the three doubles using a Scanner. Remember you need to declare a Scanner variable and then use it to call the nextDouble method of Scanner. 3. assign each of the three doubles to its own variable. At this point you have three different variables, each containing one of the doubles entered by the user. 4. compute the average. The average is computed by adding the three numbers and dividing by 3. 6. print the average. Use printf to print the result using only 2 digits after the decimal point. 7. you can run the application by typing: java ComputeAverage Examples (user input shown in boldface) % java ComputeAverage Please enter first double: 9 Please enter second double: 9 Please enter third double: 8 The numbers you entered are 9.0, 9.0, 8.0 The average is: 8.67 % java ComputeAverage Please enter first double: 10 Please enter second double: 12 Please enter third double: 11 The numbers you entered are 10.0, 12.0, 11.0 The average is: 11.00 % ComputeAverage.java import java.util.Scanner; public class ComputeAverage { public static void main(String[] args) { // variable declaration double x, y, z, avg; // scanner object Scanner sc=new Scanner(System.in); System.out.print(" Please enter first double: "); x=sc.nextDouble(); System.out.print(" Please enter second double: "); y=sc.nextDouble(); System.out.print(" Please enter third double: "); z=sc.nextDouble(); System.out.println(" The numbers you entered are: // computing average avg=(x+y+z)/3; System.out.printf(" The average is: %.2f", avg); sc.close(); "+2); 18 19 20 1234567ORGENEN2222222222222 8 9 10 11
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres your code with the corrections import javautilScanner public class ComputeAverage public ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started