A summary of Java's Method for Determining the Ping-leap year and java's Method for Determining the Ping-leap year

Source: Internet
Author: User

A summary of Java's Method for Determining the Ping-leap year and java's Method for Determining the Ping-leap year

Common method:

Import java. util. role; public class Bissextile {public static void main (String [] args) {role input = new role (System. in); // declare the scanner variable System. out. println ("Enter the year"); // The system prompts you to enter the year try {// listening exception while (true) {// continuously read the user input value int years = input. nextInt (); // obtain the Year Value of the next row if (years <1000 | years> 9999) System. out. println ("enter a year later than 1000 and less than 9999"); else if (years % 4 = 0 & years % 100! = 0 | years % 400 = 0) {// This algorithm is used to determine the System of the year. out. println (years + "");} else {System. out. println (years + "") ;}} catch (Exception e) {// Exception handling System. out. println ("Enter it correctly"); e. printStackTrace (); // print the location and cause of the error in the program }}}

General functions/methods:

Import java. util. Equals; public class Bissextile {boolean bissextile (int year) {// create a boolean type method if (year % 4 = 0 & year % 100! = 0 | year % 400 = 0) {// return true;} else {return false;} public static void main (String [] args) {Bissextile B = new Bissextile (); // create the object struct input = new struct (System. in); // declare the scanner variable System. out. println ("Enter the year"); // The system prompts you to enter the year try {while (true) {// continuously read the value int year1 = input. nextInt (); // obtain the Year Value of the next row if (year1 <1000 | year1> 9999) {System. out. println ("enter a year later than 1000 and less than 9999");} else if (B. bissextile (year1) {// object calls the bissextile method System. out. println (year1 + "");} else {System. out. println (year1 + "") ;}} catch (Exception e) {// Exception handling System. out. println ("Enter it correctly"); e. printStackTrace (); // print the location and cause of the error in the program }}}

Note: The second method uses the object-oriented idea.

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.