Program to check a Number is Even or Odd.
Program to check a Number is Even or Odd
A number is even if it is divided by 2 leaves no remainder, Otherwise it is an odd number.
Example : 16 when divide by 2 leaves no remainder So 16 is even.
19 when divide by 2 leaves 1 remainder so 19 is odd.
Algorithm :-
- Input a number in a variable
- Using if statement check if the number divide by 2 leaves any remainder
- if there is no remainder then it is even number
- else odd number
Program below:-
import java.io.*;
import java.util.*;
class Number10
{
public static void main(String args[])
{
Scanner in= new Scanner(System.in);
int n;
System.out.println("Enter No.");
n= in.nextInt(); // input number from User
if(n%2==0) // checking for even or odd
{
System.out.println("The Number is Even"); // Display message for Even Number
}
else
{
System.out.println("The Number is Odd"); // Display message for Odd Number
}
} // end of main method
} // end of class
import java.util.*;
class Number10
{
public static void main(String args[])
{
Scanner in= new Scanner(System.in);
int n;
System.out.println("Enter No.");
n= in.nextInt(); // input number from User
if(n%2==0) // checking for even or odd
{
System.out.println("The Number is Even"); // Display message for Even Number
}
else
{
System.out.println("The Number is Odd"); // Display message for Odd Number
}
} // end of main method
} // end of class
Comments
Post a Comment