Java Reference
In-Depth Information
h. This expression produces an error when it is evaluated because the first
subexpression,
((limit/count) > 7)
, involves a division by zero.
i .
true.
Since the value of the first subexpression,
(limit < 20)
, is
true
,
you know that the entire expression is
true
without bothering to evaluate the
second subexpression. Thus, the second subexpression,
((limit/count) > 7)
,
is never evaluated, so the fact that it involves a division by zero is never noticed
by the computer. This is
short-circuit evaluation
, which is what Java does.
j. This expression produces an error when it is evaluated because the first subex-
pression,
((limit/count) > 7)
, involves a division by zero.
k .
false
. Since the value of the first subexpression,
(limit < 0)
, is
false
, you
know that the entire expression is
false
without bothering to evaluate the sec-
ond subexpression. Thus, the second subexpression,
((limit/count) > 7)
,
is never evaluated, so the fact that it involves a division by zero is never noticed
by the computer. This is
short-circuit evaluation
, which is what Java does.
20. No. Since
(j > 0)
is
false
and Java uses short-circuit evaluation for
&&
, the
expression
(1/(j+1) > 10)
is never evaluated.
21.
((bonus + (((day * rate) / correctionFactor) * newGuy)) - penalty)
22.
10
7
4
1
23. There will be no output. Because
n > 0
is
false
, the loop body is executed
zero times.
24.
10
7
4
1
25.
10
A
do-while
loop always executes its body at least one time.
26. -42
A
do-while
loop always executes its body at least one time.
27. With a
do-while
statement, the loop body is always executed at least once. With
a
while
statement, there can be conditions under which the loop body is not
executed at all.
28.
2 4 6 8
29.
Hello 10
Hello 8
Hello 6
Hello 4
Hello 2