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