Java Online Compiler
Example: Leap Year Program in Java using If else Statement
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Leap Year Program in Java using If else Statement import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int y; // Value of the year System.out.println ("----Enter the year----"); y = in.nextInt(); if (y % 400 == 0) { System.out.println ("\n" + y+ " is the leap year."); } else if (y % 100 == 0) { System.out.println ("\n" + y + " is not the leap year."); } else if (y % 4 == 0) { System.out.println ("\n" + y + " is the leap year."); } else { System.out.println ("\n" + y + " is not the leap year."); } } }
2003
Output
Clear
ADVERTISEMENTS