Java Reference
In-Depth Information
EXERCISES
1. Mark the following statements as true or false:
In a counter-controlled while loop, it is not necessary to initialize the
loop control variable.
a.
It is possible that the body of a while loop might not execute at all.
b.
In an infinite while loop, the loop condition is initially false, but after
the first iteration, it is always true.
c.
d. The while loop:
j = 0;
while (j <= 10)
j++;
terminates when j > 10 .
e. A sentinel-controlled while loop is an event-controlled while loop
whose termination depends on a special value.
f. A loop is a control structure that causes certain statements to execute
over and over.
g. To read data from a file of an unspecified length, an EOF-controlled
loop is a good choice.
h. When a while loop terminates, the control first goes back to the
statement just before the while statement, and then the control goes
to the statement immediately following the while loop.
2. What is the output of the following Java code?
count = 1;
y = 100;
while (count < 100)
{
y = y - 1;
count++;
}
System.out.println("y = " + y + " and count = " + count);
3. What is the output of the following Java code?
num = 5;
while (num > 5)
num = num + 2;
System.out.println(num);
 
 
Search WWH ::




Custom Search