[Programmers]偶数と奇数(Java)


1. Problem 📃


[偶数と奇数]
https://programmers.co.kr/learn/courses/30/lessons/12937

2. Constraint 🔗



3. Solution 🔑


入力した整数が2で除算されたか否かを判別する.
1.離れなければ奇数です.
2.分けると偶数です.

4. Code 💻

class Solution {
    public String solution(int num) {
        String answer = "";
        if(num%2 == 0){
            answer = "Even";
        }
        else{
            answer = "Odd";
        }
        return answer;
    }
}