Even or Odd
Programming Basics · Java
TASK
Problem
Print `EVEN` if integer `n` is even, otherwise print `ODD`.
EXAMPLE
Example
8
EVEN
LIMITS
Constraints
-10^9 ≤ n ≤ 10^9
LEARN
Theory for this problem
+
The core idea of **Even or Odd** is to model the requested operation directly: Print `EVEN` if integer `n` is even, otherwise print `ODD`. The reference solution uses `Scanner` for input. Keep only the state needed for this result, choose numeric types that cover the stated bounds, and preserve the exact input/output contract. This makes the solution easier to verify on boundary cases and avoids unrelated work.
NEED HELP?
Hints
+
['Follow the statement for **Even or Odd** literally and identify the smallest state needed to produce its output.', 'The reference solution relies on `Scanner` for input; test the smallest allowed input and one boundary case from the constraints.']
ANSWER
Solution
+
// CodeMaster — Even or Odd
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if (n % 2 == 0) {
System.out.println("EVEN");
} else {
System.out.println("ODD");
}
}
}