I have this problem with a while loop here:
while((input = InputHandler.getInt()) != 1 && input != 2){
if(input == InputHandler.CODE_ERROR)
System.out.print("Input must be a number");
}
This while loop takes in an input only once and doesn't ask for it again, so it loops with that input taken once the entire time. What am I doing wrong here, because to me it's really strange the this wile loop is working?
InputHandler class:
public class InputHandler {
public static Scanner in = new Scanner(System.in);
public static int CODE_ERROR = -6;
public static int getInt(){
try{
return in.nextInt();
} catch(InputMismatchException e){
return CODE_ERROR;
}
}
}
inputis simultaneously equal to 1 and 2. That's not going to happen. For any value, eitherinput != 1orinput != 2is going to be true... I suspect you want&&.