
6.9 Programming Activity 1: Using while Loops 327
if ( number < 1 || number > 10 ) // INCORRECT!
{
System.out.print( “Enter a number between 1 and 10 > “ );
number = scan.nextInt( );
}
The problem with this approach is that the if statement will reprompt the
user only once. If the user enters an invalid value a second time, the pro-
gram will not catch it. A do/while loop, however, will continue to reprompt
the user as many times as needed until the user enters a valid value.
6.9 Programming Activity 1: Using while Loops
In this activity, you will work with a sentinel-controlled while loop, per-
forming this activity:
Write a while loop to process the cont ...