PhysicsTeacher.in

High School Physics + more

Write a Java program to check whether a number is even or odd

Let’s see how to write a Java program to check whether a given number is even or odd by using if-else.

Java program to determine even or odd number


import java.util.Scanner;
public class Evenodd

{
public static void main(String args[]){
int a;
Scanner sc = new Scanner(System.in);
System.out.println(“Enter the number to be tested :: “);

a = sc.nextInt();
if( a%2 == 0 )
System.out.println(“The number “+a+” is even”);

else
System.out.println(“The number “+a+” is odd”);
}
}

See also  Java program to find HCF (highest common factor) of 2 numbers
Scroll to top
error: physicsTeacher.in