Java Reference
In-Depth Information
j.
x = x + y - 5;
k.
newNum = num1 + (
int
) (4.6 / 2);
9.
Do a walk-through to find the value assigned to
e
. Assume that all variables
are properly declared.
a = 3;
b = 4;
c = (a % b) * 6;
d = c / b;
e = (a + b + c + d)/ 4;
10.
Which of the following variable declarations are correct? If a variable declaration
is not correct, give the reason(s) and provide the correct variable declaration.
n = 12;
//Line 1
char
letter = ;
//Line 2
int
one = 5, two;
//Line 3
double
x, y, z;
//Line 4
11.
Which of the following are valid Java assignment statements? Assume that
i
,
x
, and
percent
are
double
variables.
a.
i = i + 5;
b.
x + 2 = x;
c.
x = 2.5 * x;
d.
percent = 10%
12.
Write Java statements that accomplish the following.
a.
Declare
int
variables
x
and
y
.
b.
Initialize an
int
variable
x
to
10
and a
char
variable
ch
to '
B
'.
c.
Update the value of an
int
variable
x
by adding
5
to it.
d.
Declare and initialize a
double
variable
payRate
to 12.50.
e.
Copy the value of an
int
variable
firstNum
into an
int
variable
tempNum
.
f.
Swap the contents of the
int
variables
x
and
y
. (Declare additional
variables, if necessary.)
g.
Suppose
x
and
y
are
double
variables. Output the contents of
x
,
y
, and
the expression
x
+12/
y
- 18.
h.
Declare a
char
variable
grade
and set the value of
grade
to
'A'
.
i.
Declare
int
variables to store four integers.
j.
Copy the value of a
double
variable
z
to the nearest integer into
an
int
variable
x
.
13.
Write each of the following as a Java expression.
a.
32 times
a
plus
b
b.
The character that represents
8
2
Search WWH ::
Custom Search