Ask Question
13 May, 14:04

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.

+3
Answers (1)
  1. 13 May, 16:36
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers