1.8K
In order to check the number Whether a Number is Even or Odd, we have divided the number by 2 if it does not leave any remainder, the number is even otherwise number is odd.
Let’s have a look how we can implement this help of a java program.
import java.util.Scanner;
public class EvenOdd {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = reader.nextInt();
if(num % 2 == 0)
System.out.println(num + " is even");
else
System.out.println(num + " is odd");
}
}
What You get as Output , After running the program
Enter a number:25
25 is odd
Happy Programming 🙂