Java Reference
In-Depth Information
Summary of Key Concepts
A
switch
statement matches a character or integer value to one of several
possible cases.
■
A
break
statement is usually used at the end of each case alternative of a
switch
statement.
■
The conditional operator evaluates to one of two possible values based on
a boolean condition.
■
A
do
statement executes its loop body at least once.
■
A
for
statement is usually used when a loop will be executed a set number
of times.
■
The for-each version of a
for
loop simplifies the processing of all elements
in an
Iterable
object.
■
The loop statements are functionally equivalent. Which one you use should
depend on the situation.
■
A dialog box is a pop-up window that allows brief, specific user interac-
tion to provide information or verify an action.
■
Exercises
Visit
www.myprogramminglab.com
to complete many of these Exercises
online and get instant feedback.
EX 6.1
What output is produced by the following code fragment?
for
(
int
num = 0; num <= 200; num += 2)
System.out.println (num);
EX 6.2
What output is produced by the following code fragment?
for
(
int
val = 200; val >= 0; val -= 1)
if
(val % 4 != 0)
System.out.println (val);
EX 6.3
Transform the following
while
loop into an equivalent
do
loop
(make sure it produces the same output).
int
num = 1;
while
(num < 20)
{
num++;
System.out.println (num);
}
Search WWH ::
Custom Search