evelop a Java program that calculates the average of three floating-pointnumbers and displays a grade based on the average.
Question
Develop a Java program that calculates the average of three floating-point numbers and displays a grade based on the average.
Solution
Sure, here is a simple Java program that calculates the average of three floating-point numbers and displays a grade based on the average.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter three floating-point numbers:");
float num1 = input.nextFloat();
float num2 = input.nextFloat();
float num3 = input.nextFloat();
float average = (num1 + num2 + num3) / 3;
System.out.println("The average is: " + average);
if (average >= 90) {
System.out.println("Grade: A");
} else if (average >= 80) {
System.out.println("Grade: B");
} else if (average >= 70) {
System.out.println("Grade: C");
} else if (average >= 60) {
System.out.println("Grade: D");
} else {
System.out.println("Grade: F");
}
}
}
This program works as follows:
- It prompts the user to enter three floating-point numbers.
- It calculates the average of these numbers.
- It prints the average.
- It checks the average and prints the corresponding grade. If the average is 90 or above, it prints "Grade: A". If it's 80 or above but less than 90, it prints "Grade: B", and so on. If the average is less than 60, it prints "Grade: F".
Similar Questions
code this in java using patterns: Specification: Read in integers until the user enters -1. If there was at least one integer, show the average value.
Java Program To Accept the Marks of a Student and Find the Total Marks and Percentage
using the while loop, and scenner draft a java code that grades students when they enter makes it grades it with A,B+,B,C,C+ and F grades
Initialize an array/list with five integers. Write a program to find the sumand average of these numbers
18. int value = 453;19. int d1 = value % 10;20. int d2 = (value / 10) % 10;21. int d3 = (value / 100) % 10;22. System.out.println("" + d1 + d2 + d3);23. }24. }
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.