Java Reference
In-Depth Information
5.4 The while Statement
SR 5.17
An infinite loop is a repetition statement that never terminates. Specifically,
the body of the loop never causes the condition to become false.
SR 5.18
The output is the integers 0 through 9, printed one integer per line.
SR 5.19
The loop is not entered, so there is no output.
SR 5.20
Since the value of high always remains larger than the value of low ,
the code loops continuously, producing many lines of zeros, until the
program is terminated.
SR 5.21
The output is:
0 1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9 10
3 4 5 6 7 8 9 10
4 5 6 7 8 9 10
5 6 7 8 9 10
6 7 8 9 10
7 8 9 10
8 9 10
9 10
10
SR 5.22 int count = 1;
System.out.print ("divisors of " + value + ":");
while (count <= value)
{
if ((value % count) == 0)
System.out.print( "" + count);
count++;
}
SR 5.23 int count1 = 1, count2;
while (count1 <= value)
{
System.out.print ( " divisors of " + count1 + " : " );
count2 = 1;
while (count2 <= count1)
{
if ((count1 % count2) == 0)
System.out.print( "" + count2);
count2++;
}
System.out.println ();
count1++;
}
Search WWH ::




Custom Search