COP3252 Chapter 5 Flashcards
1
Q
The control variable of a counter-controlled loop should be declared as ________to prevent errors.
A
int
2
Q
Will this code count down from 10 to 1?
for ( int j = 10; j > 1; j– )
A
No
3
Q
For the code segment below:
switch( q ) { case 1: System.out.println( "apple" ); break; case 2: System.out.println( "orange" ); break; case 3: System.out.println( "banana" ); break; case 4: System.out.println( "pear" ); case 5: System.out.println( "grapes" ); default: System.out.println( "kiwi" ); } // end switch
Which of the following values for q will result in kiwi being included in the output?
A
Any number greater than or equal 4 and any number less than 1
4
Q
T or F
The break statement, when executed in a while, for or do…while, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.
A
False
5
Q
To exit out of a loop completely, and resume the flow of control at the next line in the method, use _______.
A
A break statement