24. JAVA Program To Check A Number Is Even Number or Odd Number.
How does this program work?
- In This program you are going to learn about how to check a given number is even or odd using java .
- The folowing code contains the logic to check number the given number is even or odd.
Here is the code
// To check a number even or odd.
import java.util.Scanner;public class Even
{
public static void main(String args[] )
{
int num;
System.out.println("Enter the number" );
Scanner obj1=new Scanner(System.in );
num=obj1.nextInt();
/* If number is divisible by 2 then it's an even number * else odd number*/
if(num%2==0){
System.out.println("The number is even" );
}
else
{
System.out.println("The number is odd");
}
}
}