Even or Odd Number in Java
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 and Program given below :-
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 :-
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
Note : The program is written in the easiest way possible so try understand it. If you face any problem in understanding this program than feel free to contact/comment.
All the Best :)
Keep Learning :)
Comments