본문 바로가기

개발하자/JAVA문제풀이

15.01.20 달력과제 1차(콘솔창출력)

package Calendar_Hw;

import java.util.Calendar;

public class Main {
 public static void main(String[] args) {
  Calendar calendar = Calendar.getInstance();
  int month = Integer.parseInt(args[0]);
  calendar.set(2015, month - 1, 1);
  int n = calendar.getActualMaximum(Calendar.DATE);
  System.out.println(month + "월");
  int day = 1;
  int first_day = calendar.get(Calendar.DAY_OF_WEEK);
  int u = first_day - 2;
  for (int a = 1; a < 6; a++) {
   for (int b = 1; b < 8; b++) {
    u++;
    if (u % 7 == 0) {
     System.out.println();
    }
    if (day <= n) {
     if (day == 1) {
      for (int t = 1; t < first_day; t++) {
       System.out.print("\t");
      }
     }
     System.out.print(day + "\t");
     day++;

    } else {
     continue;
    }
   }

  }
 }
}