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.