计算机技术课实验报告(6)
2012-09-24 08:13
417 查看
实验目的:
从键盘上输入一个年份,并输入一个月份(数字),输出该月份有多少天。
实验代码:
实验结果:
实验心得:
总体来说需要注意两个方面吧,其一:自然是判断当前年份是平年还是闰年的问题,当然,前面有做过,所以不会太成问题;其二:就是输出该月有多少天,当然不会是单纯的是说输出天数,是要注意2月份到底有多少天,这自然要根据输入的年份来决定,所以啊,这就将判断闰年平年联系到了一起,所以要注意喽。其他的,没有什么,就是注意不要因为粗心不小心写错代码就好了。
从键盘上输入一个年份,并输入一个月份(数字),输出该月份有多少天。
实验代码:
public class daiMa6 { public static void main(String[] args) { System.out.println("请输一个年份:"); int year = Console.readInt(); int yearCharge; if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { yearCharge = 1; } else yearCharge = 0; System.out.println("请输一个月份:"); int month = Console.readInt(); if(month > 12 || month < 0) { System.out.println("不存在该月!"); } else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { System.out.println("该月份有31天"); } else if(month == 2) { if(yearCharge == 1) { System.out.println("该月份有29天"); } else System.out.println("该月份有28天"); } else System.out.println("该月份有30天"); } }
实验结果:
请输一个年份: 2000 请输一个月份: 2 该月份有29天
实验心得:
总体来说需要注意两个方面吧,其一:自然是判断当前年份是平年还是闰年的问题,当然,前面有做过,所以不会太成问题;其二:就是输出该月有多少天,当然不会是单纯的是说输出天数,是要注意2月份到底有多少天,这自然要根据输入的年份来决定,所以啊,这就将判断闰年平年联系到了一起,所以要注意喽。其他的,没有什么,就是注意不要因为粗心不小心写错代码就好了。
相关文章推荐
- 计算机技术课实验报告(1)
- 计算机技术课实验报告(2)
- 计算机技术课实验报告7
- 计算机技术课实验报告(3)
- 计算机技术课实验报告(4)
- 计算机技术课实验报告8
- 计算机技术课实验报告(5)
- 计算机技术课实验报告11
- 计算机技术课实验报告12
- 计算机技术课实验报告9
- 计算机技术课实验报告10
- 计算机技术课实验报告13
- 计算机视觉这一年:这是最全的一份CV技术报告
- 【信息安全技术】实验报告:木马及远程控制技术
- 【机器视觉】计算机视觉这一年:这是最全的一份CV技术报告
- 《第七周实验报告3-1》---通过模板类的技术手段,设计Complex,使实部和虚部的类型为定义对象时用的实际类型
- 计算机网络原理实验报告(一)
- 计算机系统基础(bomb实验报告)
- 计算机视觉这一年:这是最全的一份CV技术报告
- 计算机安全技术实验