Java Reference
In-Depth Information
12.
int
feet = 0, inches = 0;
13.
int
count = 0;
double
distance = 1.5;
14.
distance = time * 80;
15.
interest = balance * rate;
16.
b
c
c
17.
3*x
3*x + y
(x + y)/7
Note that
x + y/7
is not correct.
(3*x + y)/(z + 2)
18.
(1/3) * 3 is equal to 0.0
Since
1
and
3
are of type
int
, the
/
operator performs integer division, which
discards the remainder, so the value of
1/3
is
0
, not
0.3333
. . . . This makes the
value of the entire expression
0 * 3
, which of course is
0
.
19.
quotient = 2
remainder = 1
20.
result is 5
21. a.
52.0
b.
9/5
has
int
value
1
; because the numerator and denominator are both of type
int
, integer division is done; the fractional part is discarded. The programmer
probably wanted floating-point division, which does not discard the part after
the decimal point.
c.
fahrenheit = (9.0/5) * celsius + 32.0;
or this
fahrenheit = 1.8 * celsius + 32.0;
22.
n == 3
23.
n
==
4
n == 3
24.
Time is money
25.
7
b
26.
defg
27.
abc
def