home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / javafile / ch02 / Parms.java < prev    next >
Encoding:
Text File  |  1998-12-14  |  1.0 KB  |  37 lines

  1. /* Parms.class prints the month and year, which are passed in
  2.  * as command-line arguments
  3.  */
  4. class Parms {
  5.  
  6. public static void main (String args[]) {
  7.  
  8. /*
  9.  * Java, unlike C/C++, does not need argument count (argc)
  10.  */
  11.         if (args.length < 2) {
  12.                System.out.println ("usage: java Parms <month> <year>");
  13. System.exit (1);
  14.         }
  15.  
  16. /*
  17.  * Unlike in C/C++, args[0] is the FIRST argument.  
  18. * The application name is not available as an argument
  19.  */
  20.         int month = Integer.valueOf (args[0]).intValue();
  21.         int year = Integer.valueOf (args[1]).intValue();
  22.         if (month < 1 || month > 12) {
  23.                System.out.println ("Month must be between 1 and 12");
  24. System.exit (1);
  25.         }
  26.         if (year < 1970) {
  27.                System.out.println ("Year must be greater than 1969");
  28. System.exit (1);
  29.         }
  30.  
  31.         System.out.print ("The month that you entered is  ");
  32.         System.out.println (month);
  33.         System.out.print ("The year that you entered is  ");
  34.         System.out.println (year);
  35. }
  36. }
  37.