Java Online Compiler
Example: Java Program to Check Even or Odd using Switch Case
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Java Program to Check Even or Odd using Switch Case import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int x; System.out.println ("Enter an integer number to check:"); x = in.nextInt(); x = x % 2 == 0 ? 1 : 0; switch(x) { // If value of "x" is 1 the input number is "Even" case 1: System.out.println ("\nThe input number is even."); break; // If value of "x" is 0 the input number is "Even" case 0: System.out.println ("\nThe input number is odd."); break; default: System.out.println ("\nInvalid case given!"); break; } } }
46
Output
Clear
ADVERTISEMENTS