Spring.java


Below is the syntax highlighted version of Spring.java from §1.2 Built-in Types of Data.



/*************************************************************************
 *  Compilation:  javac Spring.java
 *  Execution:    java day month
 *  
 *  Prints true if the given day and month fall between March 20 (inclusive)
 *  and June 20 (inclusive).
 * 
 *  %   java Spring 3 20
 *  true
 *
 *  %  java Spring 6 20
 *  true
 *
 *  % java Spring 4 15
 *  true
 *
 *  % java Spring 9 11
 * false
 *
 *************************************************************************/

public class Spring { 
    public static void main(String[] args) { 
        int month = Integer.parseInt(args[0]);
        int day   = Integer.parseInt(args[1]);
        boolean isSpring =  (month == 3 && day >= 20 && day <= 31)
                         || (month == 4 && day >=  1 && day <= 30)
                         || (month == 5 && day >=  1 && day <= 31)
                         || (month == 6 && day >=  1 && day <= 20);

        System.out.println(isSpring);
    }
}


Copyright © 2007, Robert Sedgewick and Kevin Wayne.
Last updated: Wed Jan 23 07:37:14 EST 2008.