Java---中国有句俗语叫“三天打鱼两天晒网”。某人从2010年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。
生活随笔
收集整理的这篇文章主要介绍了
Java---中国有句俗语叫“三天打鱼两天晒网”。某人从2010年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
已经实现的功能:
源代码如下:
import java.util.Scanner;public class Date {public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.print("请分别输入指定日期的年、月、日(以空格或换行为界): ");//输入提示语Scanner in = new Scanner(System.in);//键盘输入Count count = new Count(in.nextInt(),in.nextInt(),in.nextInt());//为类Count新建对象countcount.time();count.output();in.close();} }class Count {int year1;//目标年int month1;//目标月int day1;//目标日int number = 0;//初始化目标日期与2010年1月1日相差0天public Count(int year1,int month1,int day1) {//构造函数输入年月日this.year1 = year1;this.month1 = month1;this.day1 = day1;}void time() {//计算目标日期与2010年1月1日相差多少天if(year1>=2010) {for(int year = 2010;year < year1;year++){//年数增加if((year%4 == 0 && year%100 != 0) || year%400 == 0){number += 366;}else{number += 365;}}for(int month = 1;month < month1;month++){//月份增加if(month == 2){if ((year1%4 == 0 && year1%400 != 0) || year1%400 == 0){number += 29;}else {number += 28;}}else if (month == 4 || month == 6 || month == 9 || month == 11){number += 30;}else{number += 31;}}number += (day1-1);//日期增加System.out.println("距离2010年1月1日有 " + number + " 天"); }else System.out.print("");}void output() {//输出指定日期在做什么if(year1>=2010) {int result = number%5;System.out.print("根据三天打鱼两天晒网理论这天在 ");if(result == 0 || result == 1 || result == 2) {System.out.print("打鱼!");}else System.out.print("晒网!");}else System.out.print("对不起,您输入的年份小于2010,请重新输入!");}}总结
以上是生活随笔为你收集整理的Java---中国有句俗语叫“三天打鱼两天晒网”。某人从2010年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Java---简易自动取货机
- 下一篇: Java---定义一个“点”(Point