JAVA输出任意一年的日历

JAVA输出任意一年的日历

package calender;
import java.util.Scanner;
public class calender {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	System.out.println("请输入年 份:");
	int year;
	int i,m,n;
	n=0;
	year = sc.nextInt();
	for(i=1;i<year;i++) {
		if((year % 4 == 0 && year % 100 != 0)||year%400==0) {
			m=366;
			n=m+n;
		}
		else {
			m=365;
			n=m+n;
		}
	}
	int day = 1;
	System.out.println(year+"的日历:");
	int mouth ;
	int s,j;
	s=n%7+1;
	for(mouth=1;mouth<=12;mouth++){
		System.out.println(mouth+"月");
		System.out.println("日\t一\t二\t三\t四\t五\t六 ");
		if(mouth==1) {
			for(i=1;i<=(n%7+1);i++) {
				if(s==7) {
					break;
				}
				 System.out.print("\t");}
			for(;day<=31;day++) {
				System.out.print(day);
				System.out.print("\t");
				if(s==6) {
					System.out.println();}
				n++;
				s=n%7+1;}
			System.out.println();}
		else {
			int k=0;
			 if(mouth==2) {
				if((year % 4 == 0 && year % 100 != 0)||year%400==0) k=29;
				else k=28;
			}
			else if(mouth==3) k=31;
			else if(mouth==4) k=30;
			else if(mouth==5) k=31;
			else if(mouth==6) k=30;
			else if(mouth==7) k=31;
			else if(mouth==8) k=31;
			else if(mouth==9) k=30;
			else if(mouth==10) k=31;
			else if(mouth==11) k=30;
			else if(mouth==12) k=31;
			for(i=1;i<=(n%7+1);i++) {
				System.out.print("\t");}
			for(day=1;day<=k;day++) {                             
				System.out.print(day);
				System.out.print("\t");
			if(s==6) {
				System.out.println();}
			n++;
			s=n%7+1;}
			System.out.println();
		}
	}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值