Question

Write a program that prompts the user for student grades and displays the highest and lowest grades in the class.


Write a program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values.

example



Enter as many student grades as you like. Enter a character to stop.


The highest grade is: 92.0


The lowest grade is: 10.65


# in java

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class StudentMinMaxGrades {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       double min = 1000, max = -1;
       double grade;

           System.out.println("Enter as many student grades as you like. Enter a character to stop.");

       while (true) {
           try {
               grade = sc.nextDouble();
           } catch (Exception e) {
               //breaking if user enters
               break;
           }
           //checking if grade is less than min
           // make grade as min
           if (grade < min)
               min = grade;
           //checking if grade is greater than max
           // make grade as max
           if (grade > max)
               max = grade;
       }
       //printing the results
       System.out.println("The highest grade is: " + max);
       System.out.println("The lowest grade is: " + min);

   }
}

Add a comment
Know the answer?
Add Answer to:
Write a program that prompts the user for student grades and displays the highest and lowest grades in the class.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT