Java Reference
In-Depth Information
EX 2.8
What value is contained in the integer variable
length
after the
following statements are executed?
length = 5;
length *= 2;
length *= length;
length /= 100;
EX 2.9 Write four different program statements that increment the value
of an integer variable
total
.
EX 2.10 Given the following declarations, what result is stored in each of
the listed assignment statements?
int
iResult, num1 = 25, num2 = 40, num3 = 17, num4 = 5;
double
fResult, val1 = 17.0, val2 = 12.78;
a.
iResult = num1 / num4;
b.
fResult = num1 / num4;
c.
iResult = num3 / num4;
d.
fResult = num3 / num4;
e.
fResult = val1 / num4;
f.
fResult = val1 / val2;
g.
iResult = num1 / num2;
h.
fResult = (
double
) num1 / num2;
i.
fResult = num1 / (
double
) num2;
j.
fResult = (
double
) (num1 / num2);
k.
iResult = (
int
) (val1 / num4);
l.
fResult = (
int
) (val1 / num4);
m.
fResult = (
int
) ((
double
) num1 / num2);
n.
iResult = num3 % num4;
o.
iResult = num2 % num3;
p.
iResult = num3 % num2;
q.
iResult = num2 % num4;
EX 2.11 For each of the following expressions, indicate the order in
which the operators will be evaluated by writing a number
beneath each operator.
a.
a - b - c - d
b.
a - b + c - d
c.
a + b / c / d
d.
a + b / c * d
e.
a / b * c * d
f.
a % b / c * d
g.
a % b % c % d
Search WWH ::
Custom Search