runxinzhi.com
首页
百度搜索
java学习之路——小例子(实现输入年份,输出该年份的具体天数信息)
实现输入年份,输出该年份的具体天数信息。练手的代码:
package com.lcq.ThreadTest; import java.util.Scanner; public class Test2 { /** * 功能:打印出输入年份的每一天的信息 * @version 1.0 * @author lcq */ //countDays(int month, int year)函数用来计算这一年中每个月的天数 int countDays(int month, int year){ int count = -1; switch(month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: count = 31; break; case 4: case 6: case 9: case 11: count = 30; break; case 2: if(year % 4 == 0) count = 29; else count = 28; if((year % 100 ==0) & (year % 400 != 0)) count = 28; } return count; } public static void main(String[] args) { //初始化该类 Test2 t = new Test2(); System.out.println("请输入year :"); Scanner q=new Scanner(System.in); //y 变量接受输入的year int y=q.nextInt(); //遍历12个月份分别输出每一天 for (int i = 1; i <= 12; i++) { //n变量用于标记该月的天数 int n = 0; n = t.countDays(i,y); for (int j = 1; j <= n; j++) { System.out.println(i + "月" + j +"日"); } } } }
相关阅读:
[leetcode]7. Reverse Integer
[leetcode] 6. ZigZag Conversion
[leetcode] 5.Longest Palindromic Substring-2
[leetcode] 5.Longest Palindromic Substring-1
[leetcode]4. Median of Two Sorted Arrays
[leetcode]3. Longest Substring Without Repeating Characters
[leetcode]2. Add Two Numbers
[chrome]download chrome offline installer package / 下载chrome离线安装包
[powershell]powershell upgrade package
[python]python cockbook
原文地址:https://www.cnblogs.com/lcqBlogs/p/2392387.html
最新文章
Windows 环境下php安装openssl证书
PHP 按照多个键值给数组分组合并
JDBC连接数据库驱动及URL对应表
PHP 闭包(匿名函数)
系统升级win10后,wampserver开启处于offline的解决方法
[leetcode]23. Merge k Sorted Lists
[powershell] insert current time to file / Windows下插入当前时间到指定文件
[leetcode+DFS] DFS的常见写法 / 22. Generate Parentheses
[leetcode]21. Merge Two Sorted Lists
[leetcode]19. Remove Nth Node From End of List
热门文章
[leetcode]20. Valid Parentheses
[leetcode]1054. Distant Barcodes
[leetcode]15. 3Sum[UNSOLVED]
[leetcode]14. Longest Common Prefix
[leetcode]13. Roman to Integer
[leetcode]12. Integer to Roman
[leetcode]11. Container With Most Water[UNSOLVED]
[leetcode]10. Regular Expression Matching(UNSOLVED)
[leetcode]9. Palindrome Number
[leetcode]8. String to Integer (atoi)
Copyright © 2020-2023
润新知