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 +"日"); } } } }
查看全文
相关阅读:
manacher算法笔记
2019qbxtCSP-S2 模拟题1
三元环计数
踩坑日记
我的Ubuntu16.04 安装配置
SLAM14讲项目在 mac 上无法正常运行
平面最近点对的算法实现
hiho 1996
【游记】NOIP2018 退役滚粗记
铁板铮铮♂+习题集
原文地址:https://www.cnblogs.com/lcqBlogs/p/2392387.html
最新文章
关于ListView的Adapter,解决ListView滚动后内容重复的问题
Android动态设置android:drawableLeft|Right|Top|Bottom 并根据分辨率自适应
一个实用的工具,查找网站快照含历史版本
CocoStudio教程三:认识并利用CocoStudio的果实 运行2.2.1版本
对android应用一些破解的方法
[OI]主席树小结
[OI]模拟退火小结
about me
[OI][杂题]NO.1
[OI]状压DP小结
热门文章
[OI]字符串DP小结
[luogu]P2041 分裂游戏
P2480 [SDOI2010]古代猪文
【luoguP1533】可怜的狗狗
【luoguP1382】楼房
【luoguP1168】中位数
【CF10D】 LCIS
【luoguP2252】 取石子游戏
【CF848B】 Rooter's Song
【louguP2234】[HNOI2002]营业额统计(链表)
Copyright © 2011-2022 走看看