Java编写万年历
1、首先打开eclipse

3、名字起好后,点击完成

5、类的名字叫TextControl包的名字叫 com.zf.s2点击完成

7、操作打印任一年日历的类public class TextControl{static int year, monthDay, weekDay; // 定义静态变量,以便其它类调用public static boolean isLeapYear(int y) {// 判断是否是闰年return ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0));}public static int firstDay(int y) {// 计算该年第一天是星期几long n = y * 365;for (int i = 1; i < y; i++)if (isLeapYear(i))// 判断是否是闰年n += 1;return (int) n % 7;}

9、获取每个月的天数public static int getMonthDay(int m){switch (m) {case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;case 4:case 6:case 9:case 11:return 30;case 2:if (isLeapYear(year))// 判断是否是闰年return 29;elsereturn 28;default:return 0;}}

11、java程序的主入口处public static void main(String[] args) throws IOExcept足毂忍珩ion {System.out.print("请输入一个年份:");InputStreamReader ir; // 以下接受从控制台输入BufferedReader in;ir = new InputStreamReader(System.in);in = new BufferedReader(ir);String s = in.readLine();year = Integer.parseInt(s);weekDay = firstDay(year); // 计算该年第一天是星期几System.out.println("\n " + year + "年 ");printMonth();}}
