Check Even or Odd
This program checks if a number is even or odd using if-else.
Problem Statement
Write a Java program that checks if a number is even or odd.
Source Code
| 1 | public class EvenOdd { |
| 2 | public static void main(String[] args) { |
| 3 | int num = 7; |
| 4 | if(num % 2 == 0) { |
| 5 | System.out.println(num + " is even - Eduinq"); |
| 6 | } else { |
| 7 | System.out.println(num + " is odd - Eduinq"); |
| 8 | } |
| 9 | } |
| 10 | } |
Program Output
7 is odd - Eduinq
Explanation
The expression num % 2 == 0 checks divisibility by 2; if true the program prints even, otherwise it prints odd. Demonstrates if-else for decision making.