Programming and Problem Solving with Java

(やまだぃちぅ) #1

142


2.Which integer and real types take up the same number of bits in the computer’s
memory? (pp. 103–106)
3.What syntactic parts do floating-point values have that integral types lack?
(pp. 105–106)
4.If you want to change the precedence of operations in an expression, what sym-
bols do you use? (p. 114)
5.Add type casts to the following statements to make the type conversions clear
and explicit. Your answers should produce the same results as the original state-
ments. (pp. 115–118)
a.someDouble = 5 + someInt;
b.someInt = 2.5* someInt / someDouble;
6.If the Stringvariable strcontains the string “Now is the time”, what is the result
of the following expression? (pp. 126–129)
str.length() + " "+ str.substring(1, 3)
7.A value-returning method can be called either within an expression or as a sep-
arate statement. (True or False?) (pp. 122–123)
8.Write a local Java constant declaration that gives the name PIto the value
3.14159. (p. 106)
9.Declare a local intvariable named countand a local doublevariable named sum.
(pp. 107–108)
10.You want to divide 9 by 5.
a.How do you write the expression if you want the result to be the floating-
point value 1.8?
b.How do you write the expression if you want only the integer quotient? (pp.
108–111)
11.What is the value of the following Java expression? (pp. 108–109)
5 % 2
12.What is the result of evaluating the following expression? (pp. 114–115)
( 1 + 2 * 2 ) / 2 + 1
13.How would you write the following formula as a Java expression that produces a
floating-point value as a result? (pp. 115–118)

c+ 32

14.You want to compute the square roots and absolute values of some floating-
point numbers. Which Java methods would you use? (pp. 120–122)
15.Who needs to have code formatted in a clear and readable manner—the Java
compiler, the human reader, or both? (pp. 124–125)

^9

5
Free download pdf