
230 CHAPTER 5 Flow of Control,Part 1: Selection
Enter the first integer: 6
Enter the second integer: 7
Enter the third integer: 5
The smallest is 5
28 if ( num3 < smallest )
29 smallest = num3;
30
31 System.out.println( "The smallest is " + smallest );
32 }
33 }
EXAMPLE 5.5 An Application with Sequential if Statements
When the program in Example 5.5 is run using 6, 7, and 5 for the three
integers, the output is as shown in Figure 5.10.
One more point. The code only checks that one number is less than
another. What happens if two or more of the numbers are equal? The code
still works! We only need to find the smallest value; we don’t care which of
the variables ...