Java利用Calendar做万年历

源代码如下:

package com.ljl.wnl;

import java.util.Calendar;
import java.util.Scanner;

public class test {
	public static void main(String[] args) {
		Calendar calendar=Calendar.getInstance();
		Scanner sc=new Scanner(System.in);
		int count=1;
		int days;
		System.out.println("请输入年份");
		int year=sc.nextInt();
		System.out.println("请输入月份");
		int m=sc.nextInt();
		int month=m-1;
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.MONTH, month);
		calendar.set(Calendar.DATE, 0);
		if(((year%4==0&&year%100!=0)||(year%400==0))&&m==2){
			days=29;
		}else{
			days=chooseMonth(month-1);
		}
		System.out.println(year+"年"+(month+1)+"月的日历如下:");
		System.out.print("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
		while(count<=days){
			calendar.add(Calendar.DAY_OF_MONTH, 1);
			int day=calendar.getTime().getDay();
			
			if(count==1){
				for(int i=0;i

你可能感兴趣的:(Java利用Calendar做万年历)