Java Reference
In-Depth Information
is equivalent to:
result = result * (count1 + count2);
Likewise, the following statement:
result %= (highest - 40) / 2;
is equivalent to:
result = result % ((highest - 40) / 2);
Some assignment operators perform particular functions depending on the
types of the operands, just as their corresponding regular operators do. For exam-
ple, if the operands to the += operator are strings, then the assignment operator
performs string concatenation.
SELF-REVIEW QUESTIONS (see answers in Appendix N)
SR 2.21 What is the result of 19%5 when evaluated in a Java expression?
Explain.
SR 2.22 What is the result of 13/4 when evaluated in a Java expression?
Explain.
SR 2.23 If an integer variable diameter currently holds the value 5, what is its
value after the following statement is executed? Explain.
diameter = diameter * 4;
SR 2.24 What is operator precedence?
SR 2.25 What is the value of each of the following expressions?
a. 15 + 7 * 3
b. (15 + 7) * 3
c. 3 * 6 + 10 / 5 + 5
d. 27 % 5 + 7 % 3
e. 100 / 2 / 2 / 2
f. 100 / ( 2 / 2) / 2
SR 2.26 For each of the following expressions state whether they are valid or
invalid. If invalid, explain why.
a. result = ( 5 + 2 );
b. result = ( 5 + 2 * ( 15 - 3 );
c. result = ( 5 + 2 (;
d. result = ( 5 + 2 ( 4 ) );
 
Search WWH ::




Custom Search