mercredi 22 novembre 2017

Try catch with containing for and if statement Java

I am having an issue with my program. The user is able to enter a grade into a GUI, but the grade to be within grade 9 to 12.
This is what i've tried so far, but it doesn't seem to work.

int grade = Integer.parseInt(inputGrade.getText());
else
    {
        try
        {
            for (int i = 9; i < 13; i++)
            {
                if (grade == i)
                {
                grade = Integer.parseInt(inputGrade.getText());
                }
            } 
        }

        catch(NumberFormatException e)
        {            
            for (int x = -1; x < 9; x++)
            {
                if (grade == x)
                {
                outputHint.setText("Grade not valid");
                }
            }
        }

There is no hint being outputted.

Any help please? Thanks in advance!!

Aucun commentaire:

Enregistrer un commentaire