home *** CD-ROM | disk | FTP | other *** search
/ Learn Java Now / Learn_Java_Now_Microsoft_1996.iso / JavaNow / Code / Chap02 / App1_2 / App1_2.class (.txt) next >
Encoding:
Java Class File  |  1996-07-29  |  1.2 KB  |  32 lines

  1. class App1_2 {
  2.    public static void main(String[] args) {
  3.       int nMonth = Integer.parseInt(args[0]);
  4.       int nDay = Integer.parseInt(args[1]);
  5.       int nYear = Integer.parseInt(args[2]);
  6.       int nDayInYear = 0;
  7.  
  8.       for(int nM = 1; nM < nMonth; ++nM) {
  9.          switch (nM) {
  10.             case 2:
  11.                nDayInYear += 28;
  12.                if (nYear % 4 == 0 && nYear % 100 != 0) {
  13.                   ++nDayInYear;
  14.                }
  15.                break;
  16.             case 4:
  17.             case 6:
  18.             case 9:
  19.             case 11:
  20.                nDayInYear += 30;
  21.                break;
  22.             default:
  23.                nDayInYear += 31;
  24.          }
  25.       }
  26.  
  27.       nDayInYear += nDay;
  28.       System.out.print(nMonth + "-" + nDay + "-" + nYear);
  29.       System.out.println(" is day number " + nDayInYear + " in the year");
  30.    }
  31. }
  32.