Solution.1. You need to add an infinite loop (while (true))
2. Out of the loop (break;)
while(true)
{
inputString =JOptionPane.showInputDialog(null, "Enter the student ID number");
IDNumber =Integer.parseInt(inputString);
for(x = 0; x < studentsIDNumberList.length && !validIDNumber; ++x)
{
if(IDNumber == studentsIDNumberList[x])
{
validIDNumber = true;
firstName =studentsFirstNameList[x];
GPA =studentsGPAArray[x];
}
}
if(validIDNumber)
{
JOptionPane.showMessageDialog(null, "The ID number you entered is " +IDNumber + ". This number belongto "
+ firstName + " and this student GPA is " + GPA);
break;
}
else
{
JOptionPane.showMessageDialog(null, "Invalid ID number!");
}
}
Comments
Leave a comment