Determines whether a year is a leap year and a leap year.

Source: Internet
Author: User

Determines whether a year is a leap year and a leap year.

In order to make up for the time difference between the days of the human calendar and the actual cycle of the earth's revolution, a 366-day leap year was set up, with 29 days in January. The rule for determining a leap year is: if the year can be divided by four and cannot be divided by 100 or 400, the year is a leap year. Otherwise, no.

Create a LeapYear class in the project, create a scanner object in the main method of the class to accept the input year, then determine whether the year is a leap year, and finally output it on the console.

The Code is as follows:

Import java. util. principal; public class LeapYear {/*** @ param args */public static void main (String [] args) {// method stub automatically generated by TODO @ SuppressWarnings ("resource") using scan = new partition (System. in); System. out. println ("enter a year:"); long year = scan. nextLong (); if (year % 4 = 0 & year % 100! = 0 | year % 400 = 0) {System. out. print (year + "");} else {System. out. print (year + "year is not a leap year ");}}}

 

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.