Java Program: Even or Odd Checker

Code (Terminal Input)

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter a number: "); int num = sc.nextInt(); if (num % 2 == 0) System.out.println("The number is Even."); else System.out.println("The number is Odd."); } }

Input

Enter a number: 5

Output

The number is Odd.

Code (Assigned Value)

public class Main { public static void main(String[] args) { int num = 10; if (num % 2 == 0) System.out.println("The number is Even."); else System.out.println("The number is Odd."); } }

Input

Value Assigned: 10

Output

The number is Even.
Home