Java – Check Even or Odd Number
Write a Java program to check if a number of even or odd. What is an Even or Odd number?
- Even Number are not completely divisible by 2 (Eg: 1,3,5)
- Odd Number are number completely divisible by 2 (Eg: 2,4,5)
Use the below example to check a number is Even of Odd.
1 2 3 4 5 6 7 8 9 10 11 12 | public class EvenOddTest { public static void main(String[] args) { int num = 20; if ( num % 2 == 0 ) System.out.println("Odd Number"); else System.out.println("Even Number"); } } |
Compile and run this program:
javac EvenOddTest.java java EvenOddTest
Output
Odd Number