java输入年份月份,要求打印出两个月的日历

2024-11-30 23:49:23
推荐回答(3个)
回答1:

哪两个月? 

使用方法:

 public static void main(String[] args) {

  int year = 2010;

  int month = 11;

  MyCalendar curMonth = new MyCalendar(year,month);

  MyCalendar preMonth = new MyCalendar(year,month - 迹橡1);

  

  CalendarPrinter printer = new CalendarPrinter();

  printer.addCalendar(preMonth);

  printer.addCalendar(curMonth);

 清州桐 

 答坦 printer.print();

  

 }

积分加到100提供全部源码。

回答2:

import java.util.Calendar;

public class MonthUtil {

public static void main(String[] args) {

int year = 2010;
int month = 11;

printCalendarMonth(year, month);
System.out.println();
printCalendarMonth(year, month + 1);

}

static void printCalendarMonth(int year, int month) {

System.out.println("Calendar for year/mont:" + year + (month - 1)
+ "租扒\nMon\tTue\tWed\tThu\tFri\tSat\tSun");

Calendar calendar = Calendar.getInstance();

calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);

int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

for (int day = 1; day <= maxDay; day++) {
calendar.set(Calendar.DATE, day);

int weekDay = calendar.get(Calendar.DAY_OF_WEEK);

if (day == 1) {
if (weekDay != 7) {
for (int i = 1; i <= weekDay; i++) {
System.out.print(" \t"扰孙);
}
}

}

if (weekDay == 7 && day != 1) {
System.out.println();
}

System.out.print(day + "\t");
}

}

}

Calendar for year/mont:201010
Mon Tue Wed Thu Fri Sat Sun
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Calendar for year/mont:201011
Mon Tue Wed Thu Fri Sat Sun
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31

指定的月份就是year, month那里弊李昌了

回答3:

具体点啊,这样没法回答你的问题