WanNianLi

package WanNianLi;
import java.util.Scanner;
public class exercise {

	public static void main(String[] args) {
		System.out.println("请输入当前时间,中间以空格间隔:");
		Scanner in = new Scanner(System.in);
		int year = in.nextInt();
		int month = in.nextInt();
		int day = in.nextInt();
		//System.out.println(year+" "+month+" "+day);
		int todays = 0;
		boolean flag = false;
		for(int i =1900; i <year; i++){
			if(i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)){
				todays += 366;                         //把之前整年的天数相加
			}
			else
				todays += 365;
		}  
		if(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
			flag = true;
		int num = month-1;
		switch (num) {           //把当年的月份加起来
		case 12:
			todays += 31;
		case 11:
			todays += 30;
		case 10:
			todays += 31;
		case 9:
			todays += 30;
		case 8:
			todays += 31;
		case 7:
			todays += 31;
		case 6:
			todays += 31;
		case 5:
			todays += 31;
		case 4:
			todays += 30;
		case 3:
			todays += 31;
		case 2:
			if(flag) todays += 29;
			else todays += 28;
		case 1:
			todays += 31;	
		default:     
			break;
		}
		todays += day -1;      //今天距离多少天
		System.out.println("当天距离1900年1月1日有"+todays+"天");
		System.out.println("日\t一\t二\t三\t四\t五\t六\t");   //打印
		todays -= day - 1;   //打印日历时计算当月1号是星期几
		int count = todays % 7 + 1;   //使范围变到1-7
		for(int i = 0; i < count; i++){   //每月前方的空格
			if(count % 7 == 0)
				break;
			System.out.print("\t");
		}
		if(month == 1 || month == 3 || month == 5 || month == 7|| month == 8 || month == 10 || month == 12){
			for (int i = 1; i < 32; i++) {
				System.out.print(i + "\t");
				if((count + i) % 7 == 0)
					System.out.println();
			}
		}
		if(month == 4 || month == 6 || month == 9 || month == 11){
			for (int i = 1; i < 31; i++) {
				System.out.print(i+"\t");
			}
		}
		if(month == 2){
			if(flag){
				for(int i =1; i < 30; i++){
					System.out.print(i+"\t");
				}
			}
			else{
				for(int i =1; i < 29; i++){
					System.out.print(i+"\t");
				}
			}
		}
		
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值