ImportJava.util.Scanner; Public classDayu { Public Static voidMain (string[] args) {Scanner sc=NewScanner (system.in); intY =sc.nextint ();//receives the input value, does not need to define the scanner object "SC" repeatedly; intm =Sc.nextint (); intD =Sc.nextint (); intsum = 0; //determine if the input is correct if(y<2000| | m<0| | m>12| | d<0| | D>31) {System.out.println ("The date you entered is incorrect, please re-enter"); } //calculate the number of days before the year of the loss for(intk=2000;k<y;k++){ if(Isyear (y)) {//If judgment statement, if it is a Boolean value, do not need to be in the back =true| | false;Sum +=366; }Else{sum+=365; } } //calculate the number of days to lose this month for(intn=0;n<m;n++) {//Cycle for cumulative calculationSum + =Ismonth (y,m); } if((sum+d)%5==1| | (sum+d)%5==2| | (sum+d)%5==3) {//The remainder operation determines the specific number, the remainder is% not/System.out.println ("Fishing"); }Else{System.out.println ("Sun Net"); } } //Define whether the year is a leap years, if multiple calculations are required, and more complex, use a construction method, notice the type of the method return value Public Static BooleanIsyear (inty) { if((y/4==0&&y/100!=0) | | (y/400==0&&y/100==0)){ return true; }Else{ return false; } } //defines the number of days of the month output, involving several definitions of several parameters, returning the same type uniformly; Public Static intIsmonth (intYintm) { Switch(m) { Case1: Case3: Case5: Case7: Case8: Case10: Case12: return31; Case4: Case6: Case9: Case11: return30; Case2: if(Isyear (y)) {return29; }Else{ return28; } default: System.out.println ("Input Error"); return0; } }}
Title: There is an old saying in China called "Three days fishing, two days". Suppose one person starts from January 1, 2000, "Three days fishing two days", read into three integers, respectively, indicating the year, month, date, and asked the three integers that day that this person is fishing or in the net
Methods of Java:switch usage and calculation of the month