[Programmers / JAVA] Level 1 Even and Odd (12937)
[Programmers / JAVA] Level 1 Even and Odd (12937)
Complete the function solution, which returns "Even" if the integer num is even, and "Odd" if it is odd.
@RWBwritten at 2021-12-18 11:59:59
| Rank | Language Used |
|---|---|
| Level 1 | 🖼️ JAVA |
Complete the function solution, which returns "Even" if the integer num is even, and "Odd" if it is odd.
- num is an integer within the range of int.
- 0 is even.
| num | return |
|---|---|
| 3 | "Odd" |
| 4 | "Even" |
Determine whether num is odd or even, and return "Odd" if it is odd or "Even" if it is even.
You can determine this by checking whether num % 2 divides evenly or not.
JAVA
/** * Even and Odd class * * @author RWB * @since 2021.12.13 Mon 19:28:38 */ class Solution { /** * Method that returns the answer * * @param num: [int] integer * * @return [String] answer */ public String solution(int num) { return num % 2 == 0 ? "Even" : "Odd"; } }
# Programmers# Algorithm# JAVA# Level 1
