Name:     ID: 
 
Email: 

Test3

True/False
Indicate whether the statement is true or false.
 

 1. 

The assignment operator ( = ) can be combined with the arithmetic operators ( +, -, *, / ) to provide extended assignment operators, i.e. +=, -=, *=, /=.
 

 2. 

m++, m=m+1, and m+=1 are all equivalent expressions.
 

 3. 

Parameters cannot be passed as arguments to "read" methods in the KeyboardReader class, i.e. KeyboardReader.readInt( "Enter an integer: " );
 

 4. 

If a single statement follows an if or else statement the braces are not necessary, i.e.
if( ... )
   statement
else
   statement
 

 5. 

The assignment operator ( = ) and equal to operator ( == ) can be used interchangeably.
 

 6. 

A while loop will always execute at least once.
 

 7. 

Both for loops and while loops can be used as count-controlled loops.
 

 8. 

The counter in a for loop is updated at the beginning of the loop.
 

 9. 

It is illegal to declare the loop control variable inside the for loop header.
 

 10. 

A sentinel is a special value that marks the end of a list.
 

 11. 

When testing programs that use if or if-else statements, be sure to test all of the logical branches.
 

 12. 

The for statement combines counter initialization, condition test and counter update into a single expression.
 

 13. 

It is usually safer to use the == or != operators in loops, rather than the other logical operators.
 

Multiple Choice
Identify the choice that best completes the statement or answers the question.
 

 14. 

Using the same name for two different methods is called:
a.
doubling up
c.
overloading
b.
an error
d.
equivalence
 

 15. 

Which of the following methods is NOT included in the Math class?
a.
max
c.
abs
b.
min
d.
readInt
 

 16. 

Which of the following values could be returned from Random.nextInt(10)?
a.
-3
c.
11
b.
10
d.
7
 

 17. 

What type of expression returns either true or false?
a.
Boolean
c.
initialization
b.
arithmetic
d.
none of the above
 

 18. 

Which statement provides a looping mechanism that executes statements repeatedly as long as some condition is true?
a.
if
c.
while
b.
else
d.
assignment
 

 19. 

How many times will the following loop execute?
int counter = 2;
while ( counter < 10 ){
   counter += 2;
}
a.
3
c.
5
b.
4
d.
0
 

 20. 

Which statement allows a loop to terminate before the loop condition is false?
a.
end
c.
break
b.
continue
d.
stop
 

 21. 

What type of loop error occurs whenever a loop goes around one too many or one too few times?
a.
Infinite loop
c.
Initialization error
b.
Loop body error
d.
Off-by-one error
 

 22. 

What type of loop error occurs when a terminating condition is never encountered?
a.
Infinite loop
c.
Initialization error
b.
Loop body error
d.
Off-by-one error
 

 23. 

A(n) ____________ error occurs when a variable is not set to a correct starting value.
a.
Infinite loop
c.
Initialization
b.
Update
d.
Off-by-one
 

Completion
Complete each statement.
 

 24. 

There are a total of __ relational operators in Java.
 

 

 25. 

The limited precision of _____________ numbers can cause loops to execute incorrectly.
 

 

 26. 

Numbers declared as __________ have about 18 decimal digits of precision.
 

 

Short Answer
 

 27. 

What is the result of the expression (int)Math.round(3.49)?
 

 28. 

List all of the relational operators in Java.
 

 29. 

Declaring a loop control variable inside the loop header is preferable on most occasions for what two reasons.
 

 30. 

Name a good place in a loop to dump key variables with System.out.println statements, to find logic errors.
 



 
         Start Over