vendredi 30 juin 2017

Can't make String equal method and Converting Strings to Numbers work together.

It is a Java beginner question. The program is not complicated, it just asks the user input grade and then finish it when the user input "y" , and then calculate max, min,average, and total.

My trouble is that I can't stop the loop when I type y. Thank you so much, if anyone can help me out. I have tried many approaches to figure that.

    do
       { 
        System.out.println("please go on");
        input = keyboard.next();                    
        grade = Integer.parseInt(input);
        InputTimes++;
        if (grade>Maxgrade)
        {   
            Maxgrade = grade;       
         }

        if(Mingrade>grade)
        {
            Mingrade= grade;            
        }

        if (input.equals("y"))
        {   
            GameOver = true;
            System.out.println("yyyyyyy");
            break;
        }   
        else 
        {
            GameOver = false;
            System.out.println("nnnnnn");   
        }   
        totalgradeNoF = grade+totalgradeNoF;

    }while(GameOver==false);

Aucun commentaire:

Enregistrer un commentaire