dimanche 21 janvier 2018

Endless While Loop, Break Point Doesn't Work

I'm really new to Java and trying to get a hang on it. I'm trying out the code below but I'm getting a endless loop. Not sure what's wrong :(

The break point dosen't seems to help at all.

Hope you someone will be able to enlighten me :)

import java.util.Scanner;

public class Question2 {

public static void main(String[] args) {
    Scanner keyboard = new Scanner(System.in);

    System.out.print("Enter ID Number: ");
    int studentSn = keyboard.nextInt();

    System.out.print("Enter your Marks: ");
    int Score = keyboard.nextInt();

    Scanner scan = new Scanner(System.in);
    boolean stop = false;

    String answer = "";
    String Grade = "";
    String msg = "";
    int counter = 0;

    while (!stop) {

        if (Score < 50) {
            Grade = "F";
        } else if (Score <= 64) {
            Grade = "P";
        } else if (Score <= 74) {
            Grade = "C";
        } else if (Score <= 84) {
            Grade = "D";
        } else if (Score <= 100) {
            Grade = "HD";
        } else {
            msg = "Invalid Input";

        }

        if (Grade != null) {
            System.out.println("Student Serial Number: " + studentSn);
            System.out.println("Your Grade is: " + Grade);
            System.out.println("Do you want to continue (yes/no): " + answer);
        } else {
            System.out.println("Student Serial Number: " + studentSn);
            System.out.println(msg);
            System.out.println("Do you want to continue (yes/no): " + answer);
        }

        while (answer.equalsIgnoreCase("YES"));
        {
            counter++;

            if (answer.equalsIgnoreCase("NO")) {
                break;
            }
        }
    }
}

}

Aucun commentaire:

Enregistrer un commentaire