Ask Question
5 April, 03:02

Write a Java program that reads from the user four grades between 0 and 100. The program the, on separate ines, prints out the entered grades followed by the highest grade, lowest grade, and averages of all four grades. Make sure to properly label your output. Use escape characters to line up the outputs after the labels.

+1
Answers (1)
  1. 5 April, 03:29
    0
    import java. util.*;

    public class Grade {

    public static void main (String[] args) {

    Scanner input = new Scanner (System. in);

    double[] grades = new double[4];

    for (int i=0; i<4; i++) {

    System. out. print ("Enter a grade: ");

    grades[i] = input. nextDouble ();

    }

    double lowest = grades[0];

    double highest = grades[0];

    double total = 0;

    for (int i=0; i<4; i++) {

    System. out. println ("Grade " + (i+1) + " is: " + grades[i]);

    if (grades[i] > = highest)

    highest = grades[i];

    if (grades[i] < = lowest)

    lowest = grades[i];

    total + = grades[i];

    }

    double average = total/4;

    System. out. println ("The highest grade is: " + highest);

    System. out. println ("The lowest grade is: " + lowest);

    System. out. println ("The average is: " + average);

    }

    }

    Explanation:

    Ask the user for the grades and put them in the grades array using a for loop

    Create another for loop. Inside the loop, print the grades. Find highest and lowest grades in the grades array using if-structure. Also, add each grade to the total.

    When the loop is done, calculate the average, divide the total by 4.

    Print the highest grade, lowest grade and average.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a Java program that reads from the user four grades between 0 and 100. The program the, on separate ines, prints out the entered ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers