三天打鱼,两天晒网。
生活随笔
收集整理的這篇文章主要介紹了
三天打鱼,两天晒网。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
**
三天打魚,兩天曬網。
**
中國有句俗語叫“三天打魚兩天曬網”。某人從2010年1月1日起開始“三天打魚兩天曬網”,問這個人在以后的某一天中是“打魚”還是“曬網”。
首先對題目進行分析,總的來說就是需要將一個輸入的日期和初始日期進行相減,然后用所得的天數模5取余,根據余數來判斷某天是在干什么。
package zuoye4; public class Day {//定義日期的 年 月 日int year;int month;int day;int sum=0;public Day(int year,int month,int day,int sum) {//將初始的日期賦值this.year = year;this.month = month;this.day = day;}public void judge1(int year1) {for(year=2010;year<year1 ;year++) {if(year1%4==0&&year1%100!=0||year1%400==0) {//判斷是否為閏年 sum+=366;}else sum+=365;} }public void judge2(int month1){for(month=0;month<month1;month++){ // 判斷月份,2月需要分兩種情況if(month1==2){sum+=29;}else {sum+=28;}if(month1==4||month1==6||month1==9||month1==11) {//其他的月份按照天數的不同分為30天和31天兩種sum+=30*(month1-month);}else {sum+=31*(month1-month);}}}public void judge3(int day1) { // 兩個天數相減for (day=1;day<day1 ;day++) {sum+=day1-day;}}public void getsum() {//得到的天數除5取余 判斷余數為幾int activity=sum%5;switch(activity) {case 1:case 2:case 3:System.out.println("今天是打魚");//余數為1 ,2 ,3輸出打魚break;case 0:case 4:System.out.println("今天是曬網");//余數為0,4輸出曬網break;}}public static void main(String[] args) {Day a = new Day(2010,1,1,0);a.judge1(2032);a.judge2(1);a.judge3(15);a.getsum();} }總結
以上是生活随笔為你收集整理的三天打鱼,两天晒网。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: @ImportResource
- 下一篇: 图灵机实现