中国,加油!用Java写查询日历表。

时间:2020.2.12
今早起来看到微博热搜“世界卫生组织将新型冠状病毒命名为‘COVID-19’“,疫苗有可能在18个月内完成。
中国,加油!
之前看到人民日报,转发了B站大神用Java模拟演示哪几种因素会影响COVID-19的传播速度。作为芸芸大众,我们好好呆在家里,不聚会,乱跑,就能很好的控制病毒的传播。
在家宅着也是宅着,就在我要自学网上自学了Java,写了一个查询日历的小程序。(小伙伴想试试看的可以 cope 到记事本上,用 cmd 编译运行,注意:cmd 打开路径要在你保存文件的路径下打开哟。)

	import java.util.*;

public class Test35{
public static void main(String[] args){
System.out.println(“请问您想查看哪年的日历表呢?”);
Scanner input=new Scanner(System.in);
int years=input.nextInt();
System.out.println(“请问您想看”+years+“年的几月的日历表?”);
int months=input.nextInt();

	int sum=0;
	for(int year=1900;year<years;year++){
		if(year%4==0 && year%100!=0 || year%400==0){
			sum+=366;
		}else{
			sum+=365;
		}
	}

	for(int month=1;month<months;month++){
		if(month==2){
			if(years%4==0 && years%100!=0 || years%400==0){
				sum+=29;
			}else{
				sum+=28;
			}
		}else{
			if(month==4 || month==6 || month==9 || month==11){
				sum+=30;
			}else{
				sum+=31;
			}
		}
	}

	sum+=1;
	int Day=0;
	if(months==2){
		if(years%4==0 && years%100!=0 || years%400==0){
				Day=29;
		}else{
				Day=28;
		}
		}else{
			if(months==4 || months==6 || months==9 || months==11){
				Day=30;
		}else{
				Day=31;
		}
	}
	System.out.println("-----------------------------------------------------------------------");
	System.out.println("\t一\t二\t三\t四\t五\t六\t七\t");
	System.out.println("-----------------------------------------------------------------------");
	if(sum%7==0){
		System.out.print("\t\t\t\t\t\t\t");
	}else{
		for(int i=1;i<=sum%7;i++){
			System.out.print("\t");
		}
	}
	for(int i=1;i<=Day;i++){
		if(sum%7==0){
			System.out.print(i+"\n\t");
		}else{
			System.out.print(i+"\t");
		}
		sum++;  
	}
}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值