// (from the Carter book)
// Example 1 shows how DO-WHILE statements work in Java.
// The user must enter a value from 1 to 10 to exit this loop.
// Any other value will keep them in the loop.
import java.awt.*;
import hsa.Console;
public class Example1_Chapter4
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
int value;
do
{
// use a DO-WHILE loop for validation of a value:
c.println ("Give an integer (1-10)");
c.println ("which will get you out of this DO-WHILE loop");
value = c.readInt ();
}
while (value < 1 || value > 10);
} // main method
} // Example1_Chapter4 class
No comments:
Post a Comment