201
c. if(x != – 1 )
{
System.out.print(x);
System.out.print(y);
System.out.print(z);
}
else
System.out.print("y");
System.out.print("z");
8.Given this code fragment:
if(height >= minHeight)
if(weight >= minWeight)
System.out.print("Eligible to serve.");
else
System.out.print("Too light to serve.");
else
if(weight >= minWeight)
System.out.print("Too short to serve.");
else
System.out.print("Too short and too light to serve.");
a.What is the output when heightexceeds minHeightand weightexceeds
minWeight?
b.What is the output when heightis less than minHeightand weightis less than
minWeight?
9.Match each logical expression in the left column with the logical expression in
the right column that tests for the same condition.
____a. x < y && y < z (1)!(x != y) && y == z
____b.x > y && y >= z (2)!(x <= y || y < z)
____c. x != y || y == z (3)(y < z || y == z) || x == y
____d.x == y || y <= z (4)!(x >= y) && !(y >= z)
____e.x == y && y == z (5)!(x == y && y != z)
10.The following expressions make sense but are invalid according to Java’s rules of
syntax. Rewrite them so that they are valid logical expressions. (All the variables
are of type int.)
a.x< y<= z
b.x,y, and zare greater than 0
c. xis equal to neither ynor z
d.xis equal to yand z