Java Reference
In-Depth Information
3.
Suppose that
x
,
y
, and
z
are
int
variables and
x = 10
,
y = 15
, and
z = 20
.
Determine whether the following expressions evaluates to
true
or
false
.
a.
!(x > 10)
b.
x <= 5 || y < 15
c.
(x != 5) && (y != z)
d.
x >= z || (x + y >= z)
e.
(x <= y - 2) && (y >= z) || (z - 2 != 20)
4.
Suppose that
x
,
y
,
z
,and
w
are
int
variables and
x = 3
,
y = 4
,
z = 7
,and
w = 1
.
What is the output of the following statements?
a.
System.out.println("x == y: " + (x == y));
b.
System.out.println("x != z: " + (x != z));
c.
System.out.println("y == z - 3: " + (y == z - 3));
d.
System.out.println("!(z > w): " + !(z > w));
e.
System.out.println("x + y < z: " + (x + y < z));
5.
What is the output of the following Java code?
int
x = 100;
int
y = 200;
if
(x > 100 && y <= 200)
System.out.println(x + " " + y + " " + (x + y));
else
System.out.println(x + " " + y + " " + (2 * x - y));
6.
Write Java statements that output
Democrat
if the party affiliation code is
'D'
,
Republican
if the party affiliation code is
'R'
,and
independent
otherwise.
7.
Correct the following code so that it prints the correct message.
if
(score >= 60)
System.out.println("You pass.");
else
;
System.out.println("You fail.");
Suppose that you have the following declaration:
int
j = 0;
8.
The output of the statement:
if
((8 > 4) || (j++ == 7))
System.out.println("j = " + j);
is:
j = 0
Search WWH ::
Custom Search