Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class GPACalculator {
- public static void main(String []args) {
- Scanner scan = new Scanner(System.in);
- int numberOfStudents = 1;
- double studentGPA;
- int numberOfGPABelowTwo = 0;
- System.out.println();
- do {
- System.out.print("Enter student GPA for Student #" + numberOfStudents + " or (-1) to " +
- "exit" + ": ");
- studentGPA = scan.nextDouble();
- while (studentGPA < -1) {
- System.out.println("Invalid GPA value.");
- System.out.print("Enter student GPA for Student #" + numberOfStudents + ": ");
- studentGPA = scan.nextDouble();
- }
- if (studentGPA <= 2.0 && studentGPA != -1) {
- numberOfGPABelowTwo++;
- }
- numberOfStudents++;
- } while (studentGPA != -1);
- System.out.printf("%,d %s", numberOfGPABelowTwo, numberOfGPABelowTwo > 1 ? "students " +
- "have warnings." : "student has a warning.");
- } // end main
- } // end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement