Java Reference
In-Depth Information
"HEPHALUMP"
"bookkeeper"
"6789"
";+<?"
"^^^^^^^^^^"
"hephalump"
EX 5.7
What output is produced by the following code fragment?
int
num = 0, max = 20;
while
(num < max)
{
System.out.println (num);
num += 4;
}
EX 5.8
What output is produced by the following code fragment?
int
num = 1, max = 20;
while
(num < max)
{
if
(num%2 == 0)
System.out.println (num);
num++;
}
EX 5.9
What is wrong with the following code fragment? What are three
distinct ways it could be changed to remove the flaw?
count = 50;
while
(count >= 0)
{
System.out.println (count);
count = count + 1;
}
EX 5.10 Write a
while
loop that verifies that the user enters a positive
integer value.
EX 5.11 Write a code fragment that reads and prints integer values
entered by a user until a particular sentinel value (stored in
SENTINEL
) is entered. Do not print the sentinel value.
EX 5.12 Write a method called
maxOfTwo
that accepts two integer param-
eters and returns the larger of the two.
EX 5.13 Write a method called
larger
that accepts two floating point
parameters (of type
double
) and returns true if the first param-
eter is greater than the second, and false otherwise.
Search WWH ::
Custom Search