Friday, 17 June 2016

Program to know whether a number is Even or Odd.

Explanation :
If n=2 then it is an even Number.
If n=21 then it is an odd Number.

Code:

public class EvenOdd 
{
     public static void main(String[] args)
    {
     Scanner in = new Scanner(System.in);
     System.out.println("Enter a number :");
     int n = in.nextInt();
     if(n%2==0)
        System.out.println(n+" is an even number.");
     else
        System.out.println(n+" is an odd number.");
    }
}

No comments:

Post a Comment