日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

Java---中国有句俗语叫“三天打鱼两天晒网”。某人从2010年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。

發(fā)布時間:2025/5/22 java 28 豆豆

已經(jīng)實現(xiàn)的功能:

  • 從鍵盤輸入指定的年、月、日;
  • 計算從2010年1月1日至指定日期共有多少天;
  • 由于“打魚”和“曬網(wǎng)”的周期為5天,所以將計算出的天數(shù)用5去除。根據(jù)余數(shù)判斷他是在“打魚”還是在“曬網(wǎng)”;
  • 輸入結(jié)果。
  • 源代碼如下:

    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;//目標(biāo)年int month1;//目標(biāo)月int day1;//目標(biāo)日int number = 0;//初始化目標(biāo)日期與2010年1月1日相差0天public Count(int year1,int month1,int day1) {//構(gòu)造函數(shù)輸入年月日this.year1 = year1;this.month1 = month1;this.day1 = day1;}void time() {//計算目標(biāo)日期與2010年1月1日相差多少天if(year1>=2010) {for(int year = 2010;year < year1;year++){//年數(shù)增加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("根據(jù)三天打魚兩天曬網(wǎng)理論這天在 ");if(result == 0 || result == 1 || result == 2) {System.out.print("打魚!");}else System.out.print("曬網(wǎng)!");}else System.out.print("對不起,您輸入的年份小于2010,請重新輸入!");}}

    總結(jié)

    以上是生活随笔為你收集整理的Java---中国有句俗语叫“三天打鱼两天晒网”。某人从2010年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。