Java Reference
In-Depth Information
3. Trace the evaluation of the following expressions, and give their resulting values:
a. 4.0 / 2 * 9 / 2
b. 2.5 * 2 + 8 / 5.0 + 10 / 3
c. 12 / 7 * 4.4 * 2 / 4
d. 4 * 3 / 8 + 2.5 * 2
e. (5 * 7.0 / 2 - 2.5) / 5 * 2
f. 41 % 7 * 3 / 5 + 5 / 2 * 2.5
g. 10.0 / 2 / 4
h. 8 / 5 + 13 / 2 / 3.0
i. (2.5 + 3.5) / 2
j. 9 / 4 * 2.0 - 5 / 4
k. 9 / 2.0 + 7 / 3 - 3.0 / 2
l. 813 % 100 / 3 + 2.4
m. 27 / 2 / 2.0 * (4.3 + 1.7) - 8 / 3
n. 53 / 5 / (0.6 + 1.4) / 2 + 13 / 2
o. 2.5 * 2 + 8 / 5.0 + 10 / 3
p. 2 * 3 / 4 * 2 / 4.0 + 4.5 - 1
q. 89 % 10 / 4 * 2.0 / 5 + (1.5 + 1.0 / 2) * 2
4. Trace the evaluation of the following expressions, and give their resulting values:
a. 2 + 2 + 3 + 4
b. "2 + 2" + 3 + 4
c. 2 + " 2 + 3 " + 4
d. 3 + 4 + " 2 + 2"
e. "2 + 2 " + (3 + 4)
f. "(2 + 2) " + (3 + 4)
g. "hello 34 " + 2 * 4
h. 2 + "(int) 2.0" + 2 * 2 + 2
i. 4 + 1 + 9 + "." + (-3 + 10) + 11 / 3
j. 8 + 6 * -2 + 4 + "0" + (2 + 5)
k. 1 + 1 + "8 - 2" + (8 - 2) + 1 + 1
l. 5 + 2 + "(1 + 1)" + 4 + 2 * 3
m. "1" + 2 + 3 + "4" + 5 * 6 + "7" + (8 + 9)
Section 2.2: Variables
5. Imagine you are writing a personal fitness program that stores the user's age, gender, height (in feet or meters),
and weight (to the nearest pound or kilogram). Declare variables with the appropriate names and types to hold
this information.
6. Imagine you are writing a program that stores a student's year (Freshman, Sophomore, Junior, or Senior), the num-
ber of courses the student is taking, and his or her GPA on a 4.0 scale. Declare variables with the appropriate names
and types to hold this information.
7. Suppose you have an int variable called number . What Java expression produces the last digit of the number (the
1s place)?
Search WWH ::




Custom Search