Conditional Statements

WAP to Check the given number is Even or Odd number.

WAP to Check the given number is Even or Odd number.

To Check the number is even or odd, we are dividing the number by 2 and we are checking the reminder whether it is 0 or not. If the reminder is 0 then the number is completely divisible by 2 so it is even number otherwise it is the odd number.

/**********************
*@ web : ICSE JAVA MADE EASY
*@ author : ARUN KUMAR MURMU
*@program : WAP to check the number is even or odd.
*/

import java.io.*;
import java.util.*;

class EvenOdd
{
   public static void main( String arg[ ])
   {
       Scanner sc = new Scanner(System.in);
       int n = 0;
       System.out.println("Enter a number = ");
       n = sc.nextInt( ) ;
       if(n % 2 = = 0)
              System.out.println("Number is Even. ");
      else 
              System.out.println("Number is Odd. ");
   }
}

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

To Top