Self-Assessment Exercises
Chapter 5:
Program Structures
1.
Assume that you want to get user input with the
showInputDialog()
method or the
JOptionPane
class. Which import statement should you use?
a.
import java.lang.JOptionPane;
b.
import java.util.JOptionPane;
c.
import javax.util.JOptionPane;
d.
import javax.swing.JOptionPane;
2.
Suppose you want a branching statement that needs to choose between five options. Which statement type should you use?
a.
multiple
if
statements –
if
statements are easier to read than the other choices
b.
nested
if-else
statements – nested
if-else
statements are easier to use than
switch
statements
c.
switch
statement
– switch
statements are easier to read and maintain than nested
if-else
statements
d.
for
statement – this situation obviously calls for a loop
3.
AND, OR, and NOT (
&&, ||,
and
!
) are called ________ operators.
a.
Boolean
b.
logical
c.
short-cut
d.
short-circuit
4.
The
for
and
while
statements are called ________ statements.
a.
branching
b.
break
c.
continue
d.
iteration
5.
What will the following statement do?
for ( ;; )
{
…
}
a.
It will cause a syntax error; the
for
statement is missing some required parts.
b.
It will be skipped because there is no test.
c.
It will loop the maximum number of times (32,768).
d.
It will cause an infinite loop.