Though the answers do suggest the ways to resolve following the algorithm you're looking for and it could be solved with -
do {
System.out.println("Enter an Integer >= 10");
weight = input.nextInt();
} while (weight < 10);
Yet another interesting point that drew my attention to your code was, how should the following be processed
while (!input.hasNextInt()) { // this block is never reached actually
System.out.println("Please enter an integer!");
input.next(); // this is important!
}
and why did the compiler wait for an input without either printing Enter an Integer >= 10 or Please enter an integer!. And found out that's because your method call hasNextInt() awaits your input but would eventually process the next statement once you've provided some integer input (irrespective)(tried 10 and 10 10 as input as well.) The reason being the radix that is getting passed in the input provided would remain default.
Bringing this all out from the Scanner.java in the java.util
/**
* Returns true if the next token in this scanner's input can be
* interpreted as an int value in the default radix using the
* {@link #nextInt} method. The scanner does not advance past any input.
*
* @return true if and only if this scanner's next token is a valid
* int value
* @throws IllegalStateException if this scanner is closed
*/
public boolean hasNextInt() {
return hasNextInt(defaultRadix);
}
JavaDoc for hasNextInt() which in turns calls the overloaded method -
/**
* Returns true if the next token in this scanner's input can be
* interpreted as an int value in the specified radix using the
* {@link #nextInt} method. The scanner does not advance past any input.
*
* @param radix the radix used to interpret the token as an int value
* @return true if and only if this scanner's next token is a valid
* int value
* @throws IllegalStateException if this scanner is closed
*/
public boolean hasNextInt(int radix) {
setRadix(radix);
JavaDoc for hasNextInt(int radix) which calls the setRadix method.
// The next operation should occur in the specified radix but
// the default is left untouched.
private void setRadix(int radix) {
Couldn't possibly find this in the JavaDoc though.
Enter an Integer >= 10after the condition is correct ?