Page 499 - Introduction to Programming with Java: A Problem Solving Approach
P. 499
§11.6 Embedded Assignments
11. Write one Java statement that makes w, x, and y all equal to the current value of z.
§11.7 Conditional Operator Expressions
12. Suppose x equals 0.43. Given the following switch statement heading, what does the switch heading’s
controlling expression evaluate to?
switch (x>0.67 ? 'H' : (x>0.33 ? 'M' : 'L'))
§11.8 Expression Evaluation Review 13. Assume this:
int a =
int b =
float x
2;
6;
= 8.0f;
Evaluate each of the following expressions, using these guidelines:
• AsshowninSection11.8,puteachevaluationsteponaseparatelineandusethe⇒symbolbetween steps.
• Evaluateeachexpressionindependentlyoftheotherexpressions;inotherwords,usetheabove assumed values for each expression evaluation.
• Expressionevaluationproblemscanbetricky.Weencourageyoutocheckyourworkbyrunningtest code on a computer.
• Iftherewouldbeacompilationerror,specify“compilationerror.”
e) a - (b 4) % 7
f) b x 23
§11.9 Short-Circuit Evaluation
14. Assume expr1 and expr2 are expressions that evaluate to boolean values. Assume that expr1
evaluates to true. When the computer evaluates each of the following expressions, will it evaluate expr2? If yes, just say “yes.” If no, explain why, and use the term “short-circuit evaluation” in your explanation.
a) expr1 || expr2 b) expr1 && expr2
a) a 25 / (x 2)
b) 7 a * --b / 2
c) a * --b / 6 d) a b
15. Assume this: int a =
boolean
2;
flag = true;
Apago PDF Enhancer
Evaluate the following expression:
a < 3 || flag && !flag
§11.10 Empty Statement
16. Assume that the following code fragment is inside of a program that compiles successfully. What does the code fragment print? Hint: This is a trick question. Study the code carefully.
Review Questions 465