Java Reference
In-Depth Information
if (x < 0) s ++;
if (y > 0) s ++;
and
s = 0;
if (x < 0) s ++;
else if (y < 0) s ++;
Exercise R5.10 Use de Morgan's law to simplify the following Boolean
expressions.
a.
! (x < 0 && y < 0)
b.
!(x ! = 0 || y ! = 0)
c.
!(country.equals("US") && ! state.equals("HI")
&& !state.equals("AK"))
d.
!(x % 4 ! = 0 || ! (x % 100 == 0 && x % 400
== 0))
Exercise R5.11 Make up another Java code example that shows the
dangling
else
problem, using the following statement: A student with a
GPA of at least 1.5, but less than 2, is on probation; with less than 1.5, the
student is failing.
Exercise R5.12. Explain the difference between the
==
operator and the
equals
method when comparing strings.
Exercise R5.13 Explain the difference between the tests
r == s
and
r.equals(s)
where both
r
and
s
are of type
Rectangle
.
Exercise R5.14 What is wrong with this test to see whether
r
is
null
?
What happens when this code runs?