Java small case--to determine whether the given year is a common year or leap years

Source: Internet
Author: User

Requirements:
* Determine whether the year entered by the user is common year or leap years

Implementation code:

ImportJava.util.Scanner;/*** Required: * To determine whether the year entered by the user is common year or leap years *@authorAdministration **/ Public classJudge { Public Static voidMain (string[] args) {Scanner input=NewScanner (system.in); System.out.println ("Please enter a year:"); LongYear =Input.nextlong (); //leap years need to meet the conditions: can be divisible by 4 but not divisible by 100, or can be divisible by 400, to meet one can        if((year%4==0 && year%100!=0) | | year%400==0) {System.out.println ( year+ "Years is a leap year! "); }Else{System.out.println ( year+ "Year is common year!" "); }    }}

Operation Result:

Please enter a year:1000 is common year! 
Please enter a year:2000 is leap years! 

Java small case--to determine whether the given year is a common year or leap years

Related Article

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.