从键盘分别输入年、月、日,判断这一天是当年的第几天
2022/1/20 23:22:26
本文主要是介绍从键盘分别输入年、月、日,判断这一天是当年的第几天,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import java.util.Scanner; class Exer1 { public static void main(String[] args) { Scanner scan = new Scanner (System.in); System.out.print("年:"); int year = scan.nextInt(); System.out.print("月:"); int month = scan.nextInt(); System.out.print("日:"); int day = scan.nextInt(); int days = day;//如果将days 初值设置为0,则可以加上case1: days += day; //加前面几个月的满月天数 switch(month){ case 12: //前面11个月的总天数 //days += 第11月的天数; days += 30; case 11: //前面10个月的总天数 //days += 第10月的天数; days += 31; case 10: days += 30;//九月 case 9: days += 31;//八月 case 8: days += 31;//七月 case 7: days += 30;//六月 case 6: days += 31;//五月 case 5: days += 30;//四月 case 4: days += 31;//三月 case 3: days += 28;//二月 /*if(闰年){ days++; } */ if(year % 4 ==0 && year % 100 != 0 || year%400==0){ days++; } case 2: days += 31;//一月 } System.out.println(year + "年" + month + "月" + day + "日是这一年的第" + days + "天"); } }
这篇关于从键盘分别输入年、月、日,判断这一天是当年的第几天的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?
- 2024-05-09企业src漏洞挖掘-有意思的命令执行