Page 501 - Introduction to Programming with Java: A Problem Solving Approach
P. 501
3
4
5
6
7
• AsshowninSection11.8,puteachevaluationsteponaseparatelineandusethe⇒symbolbetween steps.
• Evaluateeachexpressionindependentlyoftheotherexpressions;inotherwords,usetheaboveas- sumed values for each expression evaluation.
• Expressionevaluationproblemscanbetricky.Weencourageyoutocheckyourworkbyrunningtest code on a computer.
• Iftherewouldbeacompilationerror,specify“compilationerror.”
a) a - 7 /
b) 8 + a *
c) a + b--
(x - 4)
++b / 20
d) a + (b = 5) % 9
e) a = x = -12
7. [after §11.8] Assume this: String s = "hi";
int num = 3;
char ch = 'm';
Evaluate each of the following expressions. Follow these guidelines:
• AsshowninSection11.8,puteachevaluationsteponaseparatelineandusethe⇒symbolbetween steps.
• Evaluateeachexpressionindependentlyoftheotherexpressions;inotherwords,usetheaboveas- sumed values for each expression evaluation.
• Expressionevaluationproblemscanbetricky.Weencourageyoutocheckyourworkbyrunningtest Apago PDF Enhancer
code on a computer.
• Iftherewouldbeacompilationerror,specify“compilationerror.”
a) s + (num + 4)
b) s + num + 4
c) s + '!' + "\""
d) num + ch
e) '8' + 9
8. [after §11.9] Consider the following code fragment. Line numbers are at the left.
1
int a = 2;
boolean b = false;
boolean c;
c = b && ++a == 2;
b = a++ == 2;
b = !b;
System.out.println(a + " " + b + " " + c);
2
Trace the code using this trace setup:
Exercises 467
line#
a
b
c
output
9. [after §11.9] Assume: boolean a = false;
boolean b;
double c = 2.5;