Check Even Odd Number in Java
Here you will get example code to check weather the given number is even or odd. Lets understand the coding of Even or Odd Program in Java.
This program is used to demonstrates the simple use of if-else by checking the number using the modules operator.
Example code of Even or Odd program in Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | //Program to check Even Odd Number in Java class checkEvenOdd { public static void main(String str[]) { int a; a=Integer.parseInt(str[0]); if(0==a%2) { System.out.println("given no. is="+a); System.out.println("Number is Even "); } else { System.out.println("given no. is="+a); System.out.println("Number is Odd "); } } } |
Output
Check out our other Java Programming Examples