zoukankan
html css js c++ java
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 +"日"); } } } }
查看全文
相关阅读:
poj2954
bzoj1863
bzoj2002
bzoj1389
[POJ3041] Asteroids(最小点覆盖-匈牙利算法)
[POJ2594] Treasure Exploration(最小路径覆盖-传递闭包 + 匈牙利算法)
[POJ2446] Chessboard(二分图最大匹配-匈牙利算法)
[luoguP1266] 速度限制(spfa)
[luoguP1186] 玛丽卡(spfa)
[luoguP1027] Car的旅行路线(Floyd)
原文地址:https://www.cnblogs.com/lcqBlogs/p/2392387.html
最新文章
mysql远程连接报错: Host * is not allowed to connect to this MySQL server,解决方法
mysql多实例
mysql-cmake编译
安装mysql
[手游新项目历程]第23天-map下标访问阻塞线程
慢性湿疹药物
[手游新项目历程]第24天-pthread
无法连接app store
[手游新项目历程]-25- memcpy() -rep movsd ,N
值得看的电影和连续剧
热门文章
[手游新项目历程]-26- mysqld-debug-release
农行提额度
[手游新项目历程]-27- GetQueuedCompletionStatus内存泄漏
工行刷星
bzoj1832
bzoj1303
poj1150
poj1637
poj3519
poj2151
Copyright © 2011-2022 走看看