I have a do while loop. Checking x is between two values. Now im supposed to be taking in an int value, but if the user types a double im getting exceptions. How do I incorparate a check in the same if statement so that if the user types a double it would print something like "x must be an int between 10 and 150:"
do {
x = sc.nextInt();
if ( x < 10 || x > 150 ) {
System.out.print("x between 10 and 150: ");
} else {
break;
}
nextDoubleinstead ofnextInt? Then check whether the specified value is equal to its integer equivalent? Admittedly that would allow "100.000" as valid input - is that a problem?xto be between 10 and 50, your condition is wrong. You should change it tox > 10 || x < 150^Chaha\b\b\bnot a number, you fool!x >= 10 && x <= 150