// (from the Carter book)
// If we want to have the ELSE associated with the first IF, the preferred
// solution is to use brace brackets to "close off" the second IF, as shown
// below. This works if 'p' and 'q' are both set to true, but not if 'q'
// is set to false (while 'p' is still true). If 'p' is also false, it works too.
import java.awt.*;
import hsa.Console;
public class Chapter3_Example4Bi
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
boolean p = true, q = true;
if (p)
{
if (q)
c.println ("Take Path 1A");
}
else
c.println ("Take Path 2A");
p = false;
q = false;
if (p)
{
if (q)
c.println ("Take Path 1B");
}
else
c.println ("Take Path 2B");
} // main method
} // Chapter3_Example4Bi class
No comments:
Post a Comment