Java program to check the given number is even or odd
KW.java
import java.util.Scanner;
class KW 
{
    public static void main(String args[])
    {
        int x;
        Scanner sc=new Scanner(System.in);
        System.out.println("———————————————————————————————————————————");
        System.out.println("Program for even-odd test of a given number");
        System.out.println("———————————————————————————————————————————");
        System.out.print("Enter a number ");
        x=sc.nextInt();
        //if((x>>1)<<1==x)
        if(x%2==0)
        {
            System.out.println("\nEntered number is EVEN");
        }
        else
        {
            System.out.println("\nEntered number is ODD");
        }
        System.out.println("———————————————————————————————————————————");
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW ——————————————————————————————————————————— Program for even-odd test of a given number ——————————————————————————————————————————— Enter a number -5005 Entered number is ODD ——————————————————————————————————————————— kodingwindow@kw:~$
What Next?
Java Loops
Advertisement