Write A Java Program To Find Number Is Even Or Odd :



import java.util.Scanner;

class EvenOdd
{

     {
            public static void main( String args[] )
    
      int x;
      

      Scanner s =  new Scanner(System.in);

      System.out.println("Enter Number To Check It Even Or Odd");


           x =  s.nextInt();
 
            if( x % 2 == 0 )

            {
                  System.out.println( x + " is Even " );

             }
                  System.out.println( y + " is Odd " );

  }


Out Put-


 C:\Users>javac  EvenOdd.java

 C:\Users>

 C:\Users>java  EvenOdd

 C:\Users>Enter Number To Check It Even Or Odd

C:\Users>4

C:\Users>4 is even number







In this program first we have import java.util.Scanner class. Scanner class is use for get values from user on consol. then we have create class which having main method in class. 

then next we defin integer variable 'int x'
create Scanner class object as 's' in this object 's' store the value of 'x' which is  enter by user. 

then print message on consol to get number by user.
then use Int method to access number from user.

we have use if condition to check number is even or not by condition x %(mod) 2 = 0 . then print number is even or not . 






How To Execute Program -

firstly save program with same name of class name with java extension. 
then open cmd ( comand prompt ) in path of this program and compile the program by 'javac filename.java' comand. 
after compiled program, run the program by 'java filename' comand.