Java Reference
In-Depth Information
EX 5.2
What is wrong with the following code fragment? Rewrite it so
that it produces correct output.
if
(total == MAX)
if
(total < sum)
System.out.println ("total == MAX and < sum.");
else
System.out.println ("total is not equal to MAX");
EX 5.3
What is wrong with the following code fragment? Will this code
compile if it is part of an otherwise valid program? Explain.
if
(length = MIN_LENGTH)
System.out.println ("The length is minimal.");
EX 5.4
What output is produced by the following code fragment?
int
num = 87, max = 25;
if
(num >= max*2)
System.out.println ("apple");
System.out.println ("orange");
System.out.println ("pear");
EX 5.5
What output is produced by the following code fragment?
int
limit = 100, num1 = 15, num2 = 40;
if
(limit <= limit)
{
if
(num1 == num2)
System.out.println ("lemon");
System.out.println ("lime");
}
System.out.println ("grape");
EX 5.6
Put the following list of strings in lexicographic order as if deter-
mined by the
compareTo
method of the
String
class. Consult the
Unicode chart in Appendix C.
"fred"
"Ethel"
"?-?-?-?"
"{([])}"
"Lucy"
"ricky"
"book"
"******"
"12345"
" "
Search WWH ::
Custom Search