blog.itcode.devblog.itcode.dev

[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.

[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.
RWB0104
@RWBwritten at 2021-12-18 11:59:59
Programmers

시리즈 모아보기

Programmers

56 / 78
RankLanguage Used
Level 1

🖼️ JAVA

🔗 Even and Odd

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.
numreturn
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
ship
blog.itcode.dev

Notes from the π-th Alpaca

7.0.1
Developed by RWB since 2021.057th upgraded at 2026.08