Methods of Java:switch usage and calculation of the month

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.