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 the greatest and smallest numbers
Scroll to top
error: physicsTeacher.in