public static void main(String[] args) {
    int month = calendar.get(MyCalendar.MONTH) + 1;
    int year = calendar.get(MyCalendar.YEAR);

    if (args.length > 2) System.out.println("Usage java Exercise14_10 month year");
    else if (args.length == 2) {
      // use user-defined month and year
      year = Integer.parseInt(args[1]);
      month = Integer.parseInt(args[0]);

      calendar.set(Calendar.YEAR, year);
      calendar.set(Calendar.MONTH, month - 1);
    } else if (args.length == 1) {
      // use user-defined month for the current year
      month = Integer.parseInt(args[0]);

      calendar.set(Calendar.MONTH, month - 1);
    }

    // set date to the first day in a month
    calendar.set(Calendar.DATE, 1);

    // print calendar for the month
    printMonth(year, month);
  }
  static void printMonth(int year, int month) {
    // get start day of the week for the first date in the month
    int startDay = getStartDay();

    // get number of days in the month
    int numOfDaysInMonth = calendar.daysInMonth();

    // print headings
    printMonthTitle(year, month);

    // print body
    printMonthBody(startDay, numOfDaysInMonth);
  }
 static void printMonthTitle(int year, int month) {
   System.out.println("         " + calendar.getMonthName() + ", " + year);
   System.out.println("-----------------------------");
   System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
 }
 static int getStartDay() {
   return calendar.get(Calendar.DAY_OF_WEEK);
 }