A detailed explanation and an example of java's leap year judgment

  • 2020-06-15 08:34:02
  • OfStack

java leap year judgment

Preface:

Given a year, determine if the year is a leap year.

The year is a leap year when 1 of the following is true:

1. The year is a multiple of 4, not 100;

2. Years are multiples of 400.

All other years are not leap years.

Input format

The input contains 1 integer y, representing the current year.

The output format

Output 1 row, yes if the given year is a leap year, no if not.

Note: When the question specifies that you should output 1 string as a result (yes or no, for example), you need to follow the case specified in the question.

The sample input

2013

Sample output

no

The sample input

2016

Sample output

yes

Data size and conventions

1990 < = y < = 2050.




import java.util.Scanner; 
 
public class Main { 
 
  public static void main(String[] args) { 
    // TODO Auto-generated method stub 
    int year; 
    Scanner scanner = new Scanner(System.in); 
    year = scanner.nextInt(); 
    if( (year%4==0&&year%100!=100)||year%400==0) 
      System.out.println("yes"); 
    else { 
      System.out.println("no"); 
    scanner.close(); 
    } 
  } 
 
} 

Thank you for reading, I hope to help you, thank you for your support to this site!


Related articles: