Normal method:
import java.util.Scanner; public class Bissextile{ public static void main(String[] args){ Scanner input=new Scanner(System.in);//Declare the scanner variable System.out.println("Please enter year");//The system prompts to enter year try{ //Speak out exception while(true){ //Continuously read the value entered by the user int years=input.nextInt();//Get the year value entered in the next line if (years<1000||years>9999) System.out.println("Please enter year greater than 1000 and less than 9999"); else if(years % 4 == 0 && years % 100 != 0 || years % 400 == 0){ //Platinum leap year judgment algorithm System.out.println(years+"year is leap year"); } else { System.out.println(years+"year is a normal year"); } } } catch(Exception e){ //Exception handling System.out.println("Please enter correctly"); e.printStackTrace(); //Print the location and reason of the error in the program} } } }General functions/methods:
import java.util.Scanner;public class Bissextile { boolean bissextile(int year){ // Method for creating boolean type if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){ //Flat leap year judgment algorithm return true;}else{return false;}}public static void main(String[] args){Bissextile b=new Bissextile(); //Create object Scanner input=new Scanner(System.in);//Declare the scanner variable System.out.println("Please enter year");//The system prompts to enter year try{while(true){ //Continuously read the value entered by the user int year1=input.nextInt();//Get the year value entered in the next line if (year1<1000||year1>9999){System.out.println("Please enter year greater than 1000 and less than 9999");}else if(b.bissextile(year1)){ //The object calls the bissextile method System.out.println(year1+"is a leap year");}else{System.out.println(year1+"is a common year");}}}}catch(Exception e){ //Exception handling System.out.println("Please enter correctly"); e.printStackTrace(); //Print the location and reason of the error in the program}}}}Note: The second method uses the object-oriented idea