没有合适的资源?快使用搜索试试~ 我知道了~
编写JAVA程序,判断是否闰年,输出月份天数
5星 · 超过95%的资源 需积分: 50 64 下载量 29 浏览量
2011-05-17
15:56:02
上传
评论 1
收藏 29KB DOC 举报
温馨提示
试读
1页
编写Java程序,输出1900年到2010年之间的所有润年,并从键盘上输入任意年月,输出该年是否闰年及这个月有多少天。
资源推荐
资源详情
资源评论
package syj;
import java.util.Scanner;
public class runyear {
public static void main(String[] args) {
System.out.print("输入年份:");
Scanner sc = new Scanner(System.in);
int year = sc.nextInt();
//设置布尔型变量存满足闰年的条件
if(year<=1900||year>=2010)
{System.out.println(year + "您输入的年份不在范围内!");}
else {};
boolean isRn = (year % 4 == 0) && (year % 100 != 0)||(year%400==0);
//用if-else结构判断输入年份是否为闰年
if (isRn) {
System.out.println(year + "年是闰年");
} else {
System.out.println(year + "年是平年");
}
System.out.print("输入月份:");
int month = sc.nextInt();
//多重if结构判断输入月份的天数
if (month==1||month==3||month==5||month==7||month==8||
month==10||month==12)
{
System.out.println(year + "年" + month + "月的天数是31");
} else if ((month==2) && isRn) {
System.out.println(year + "年" + "2" + "月的天数是29");
} else if ((month==2) && !isRn) {
System.out.println(year + "年" + "2" + "月的天数是28");
} else if (month==4||month==6||month==9||month==11) {
System.out.println(year + "年" + month + "月的天数是30");
} else {
System.out.println("输入的月份不正确");
}
}
}
资源评论
- 安静的蜗牛2013-01-30最近的一段程序里面要用到这个。实在是懒得写。谢谢分享。
- 清冷2012-08-23嗯,这个代码很不错.老师布置的作业,我不太会.参考了代码发现代码思路清晰,效果也很好.谢谢
- xiaodeng2014-12-20还不错,先保存了
- Colin19492012-06-19挺好 闰年,二月29..
MT_maotutu
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功