I'm doing some Java homework and I can't get this while loop to work correctly.
I've tried to editing the code, but it keeps giving errors.
while(true) {
System.out.println("Is student a TA? (1: YES 0: NO): ");
status = inReader.nextInt();
if (status == 1) {
status1 = true;
}
else if (status == 0) {
status1 = false;
}
else {
System.out.println("Please enter valid entry.");
}
Graduate grad = new Graduate(studentID, name, major, status1);
grad.displayStudentData();
}
}
}
}
I want the code to loop back if the user inputs anything other than a 0 or 1. It does loop back but the information gets outputted to the console. Which is not what I was hoping it would do.
continueandbreak? Inserting one of each into your code in the right place will make it behave like you want to.