Java Reference
In-Depth Information
SR3
.
if
(z > 0) {
x= 0;
y= y + 1;
}
SR4
.
if
(z > 0) {
z= x;
x= y;
}
SR5
.
if
(x
+
y <= x - y) { //
you could write the condition as
y<=0
z= x + y;
}
else
{
z= x - y;
}
SR6
.
//
Set
d
to the minimum of
a
,
b
, and
c
if
(a <= b && a <= c) {
d= a;
}
else
if
(b <= c) {
d= b;
}
else
{
d= c;
}
SR7
.
//
Set
d
to the maximum of
a
,
b
, and
c
if
(a<b||a<c) {
if
(b >= c) {
d= b;
}
else
{
d= c;
}
}
else
{ //
This else belongs with the first
if
, not the second.
d= a;
}
SR8
. There are several ways to write this program segment. The following one
illustrates nested if-statements:
if
(b + c < d) { t=
false
; }
else if
(c + d < b) { t=
false
; }
else if
(d + b < c) { t=
false
; }
else
{ t=
true
; }
Here is a neater solution:
t= (b+c>=d)&&(c+d>=b)&&(d+b>=c);
Search WWH ::
Custom Search