PhysicsTeacher.in

High School Physics

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  Automorphic Number Java Program – check if a Number is an Automorphic
Scroll to top
error: physicsTeacher.in