// (from the Carter book)
// Nested IF statements. (new and improved version of Example 1).
// That is, if x is negative, only 1 test is performed, while if x is
// positive or zero, only 2 tests are performed. In no case is it
// necessary to perform 3 tests.
import java.awt.*;
import hsa.Console;
public class Chapter3_Example2
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
int x = 10;
if (x < 0)
c.println ("x value is negative");
else
if (x > 0)
c.println ("x value is positive");
else
c.println ("x value is zero");
} // main method
} // Chapter3_Example2 class
No comments:
Post a Comment