// (from the Carter book)
// Questions 1, 2 and 3 of Exercise 4.1 (WHILE loops):
// Questions 1 and 2 can be answered in text here, but
// Question 3 consists of Java code which must be runnable
// in order to produce output.
import java.awt.*;
import hsa.Console;
public class Exercise41_Chapter4
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
// Question 1:
// What is the minimum number of times that the body of a while
// statement can be executed? 0 times.
// Question 2:
// What is the maximum number of times that the body of while
// statement can be executed? No maximum.
// Question 3:
// What will be printed by this fragment?
int m = 10;
int n = 0;
while (m > n)
{
c.println ("m = " + m + " n = " + n);
m--;
n += 2;
}
} // main method
} // Exercise41_Chapter4 class
No comments:
Post a Comment