Java Assignment First, launch NetBeans and close any previous projects that may
ID: 3875515 • Letter: J
Question
Java
Assignment
First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).
Then, create a new Java application called "AverageCalculator" (without the quotation marks) that prompts the user with three separate prompts for three numbers (use double values for these), computes the average of those three doubles (use a double for the average), and then prints out explanatory text, the three numbers, and their average, printed with 2 decimal places. (See Horstmann, Section 2.3.2, pp. 50-52 for some ideas.)
For example, if the user gives your program the numbers 30, 100, and 21, your output should look very much like the following: The average of the numbers 30.00, 100.00, and 21.00 is 50.33.
thank you
Explanation / Answer
import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
float x=30;
float y=100;
float z=21;
float average=(x+y+z)/3;
System.out.print("the average of");
System.out.println(String.format("%.2f", x) +","+ String.format("%.2f", y) +","+String.format("%.2f", z)+"="+String.format("%.2f", average));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.