The first stage of Java Learning-function application-Calendar function

Source: Internet
Author: User

ImportJava.util.Scanner; Public classP06 { Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner input =NewScanner (system.in); System.out.print ("Please enter a year (greater than 1900):"); intYear=Input.nextint ();  while(year<1900) {System.out.print ("The year you entered has an error, please re-enter:"); year=Input.nextint (); } System.out.print ("Please enter a month:"); intMonth=Input.nextint ();  while(month<1| | Month>12) {System.out.print ("The entered month has an error, please re-enter:"); Month=Input.nextint (); }        //if (isleapyear (year)) {//System.out.println (year+ "Years is a leap year");//        }//else{//System.out.println (year+ "is not a leap year");//        }//        //System.out.println (year+ "year" +month+ "Month has" +getdaysofmonth (year,month) + "Days");//        //System.out.println (year+ "year" +month+ "month 1th" is the "+getdayofthisyear (year, month) +" Day ");//        //System.out.println ("From 1900 to" +year+ "years (excluding the year) is a total of" +getcrossdays "+" days ";//System.out.println ("t \ t two \ t three \ Four \ five \ t six");  for(inti = 0; I <isdayofweek (year, month); i++) {System.out.print ("\ T"); }         for(inti = 1; I <=getdaysofmonth (year, month); i++) {System.out.print (i+ "\ T"); if(I==7-isdayofweek (year, month) | | (I-7+isdayofweek (year, month))%7==0) {System.out.println (); }            }            }    /*** Determine if it is a leap year *@paramYear *@return     */     Public Static BooleanIsleapyear (intYear ) {        returnYear%4==0 && year%100!=0 | | Year%400==0; }    /*** Returns the number of days of the month *@paramYear *@paramMonth *@return     */     Public Static intGetdaysofmonth (intYearintmonth) {        if(month==2) {            if(Isleapyear (year)) {return29; }            Else{                return28; }        }        Else if((month<8 && month%2!=0) | | (month>7&&month%2==0)){            return31; }        Else {            return30; }    }    /*** Returns the first day of the year *@paramYear *@paramMonth *@return     */     Public Static intGetdayofthisyear (intYearintmonth) {        intSum=0;  for(inti = 1; I <=month-1; i++) {sum+=Getdaysofmonth (year, i); }        returnSum+1; }    /*** Calculate the number of days from 1900 to the year (excluding the year)@paramYear *@return     */     Public Static intGetcrossdays (intYear ) {        intSum=0;  for(inti = 1900; I < year;i++) {             for(intj = 1; J <=12; J + +) {sum+=Getdaysofmonth (i, j); }        }        returnsum; }    /*** Calculate the number of days of day 1th of the month (known as 1900-1-1 is Monday) *@paramYear *@paramMonth *@returnback (0~6) corresponds from Sunday to Saturday*/     Public Static intIsdayofweek (intYearintmonth) {        intSum=getcrossdays (year) +Getdayofthisyear (year, month); returnSum%7; }}

The first stage of Java Learning-function application-Calendar function

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.