Answers for Expression & Assignment Worksheet for Java
You may only use calculators for arithmetic. Do not enter entire expressions. There will be no calculators
permitted for the test/s.
1.
2.
A name for a data storage area in memory.
A programmer defined word used to name a variable,
constant, method, etc.
3. 1
4. A value that will never change, ex. PI = 3.14159...
5. One or more terms that can be evaluated to a single value.
6. The four integer data types are: byte, short, int, and long.
7. The floating point data types are: float and double.
8. An escape sequence is used to include reserved symbols in
output.
9. Precedence is the order in which the computer will execute
operators.
10. In narrowing conversions, data can be lost. Not so with
widening.
11. The new operator creates an instance (object) of a class.
12.
a) w * z
b) w * z + y
2 * 12
2 * 12 + 7
24
24
+ 7
31
c) w * -z
d) w * --z + y++
2 * -12
2 * --12 + 7++
-24
22
+ 7
29
z=11 & y=8
e) w * z-- + ++y
f) w + z * y
2 * 12-- + ++7
2 + 12 * 7
24
+
8
2 +
84
32
86
z=11 & y=8
g) w - y + z
h) (w + y) * z
2 - 7 + 12
(2 + 7) * 12
-5 + 12
9
* 12
7
108
i) y / w
j) y / z
7 / 2
y / 12
3
0
k) w % w
l) y % w
2 % 7
7 % 2
2
1
13.
a) w
/ z
b) z
/ w
12.9 / 12.2
12.2 / 12.9
1.05..
0.94..
c) w
/ z
- y
12.9 / 12.2 - 3.2
1.0573..
- 3.2
-2.14..
d) w
- z
* y
12.9 - 12.2 * 3.2
12.9 39.04
-26.14
D:\687293224.doc
© 2003, Louis A. Trentini. All rights reserved.
e) (w
- z)
* y
(12.9 - 12.2) * 3.2
0.7
* 3.2
2.24
f) z
/ y
/ w
12.2 / 3.2 / 12.9
3.8125
/ 12.3
0.30..
g) z
/ (y
/ w)
12.2 / (3.2 / 12.9)
12.2 /
0.24..
49.18..
h) y
% z
3.2 % 12.2
3.2
this now works
14.
a)
b)
w
y
z
w
y
5
9
2
5
9
45
z
2
11
c)
w
5
y
9
1
z
2
y
9
17
z
2
e)
w
5
y
9
4
z
2
d)
w
5
y
9
19
z
2
f)
w
5
15.
a)
a^=^a
b)
a^=^a
c)
163
d)
This is fun. 
e)
12
16. To save space, I've continued using the original
variable names.
a)
SA = 4 * PI * r * r;
b)
V = 4 * PI * r * r * r / 3;
c)
A = Math.sqrt(s*(s-a)*(s-b)*(s-c))
d)
D = Math.sqrt((x2-x1)*(x2-x1) +
(y2-y1)*(y2-y1));
e)
X1 = (-b + Math.sqrt(b*b-4*a*c))
/ (2*a);
X2 = (-b - Math.sqrt(b*b-4*a*c))
/ (2*a);
Download

Expression & Assignment Worksheet Answers