满意答案
ZKircheis
2015.09.14
采纳率:42% 等级:8
已帮助:611人
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566import java.util.Calendar;import java.util.Date;import java.util.Scanner; public class Test{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String reg = "^(\\d+)[^\\d]+((0?[1-9])|(1[012]))$"; while(true) { System.out.println("输入年月(年和月用非数字隔开:如2015.1)(什么都不输入直接退出)"); String line = scanner.nextLine().trim(); if("".equals(line)) { scanner.close(); break; } if(!line.matches(reg)) { continue; } int year = Integer.parseInt(line.replaceAll(reg, "$1")); int month = Integer.parseInt(line.replaceAll(reg, "$2")); System.out.println("日\t一\t二\t三\t四\t五\t六"); Calendar calendar = Calendar.getInstance(); // 这个月的1号是星期几 calendar.set(year, month - 1, 1); int day = calendar.get(Calendar.DAY_OF_WEEK); int start = Calendar.SUNDAY; calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - day + start); while(start
00分享举报