[JAVA] 프로그래머스 : 이어 붙인 수

조예빈·2024년 8월 7일
0

Coding Test

목록 보기
97/138

https://school.programmers.co.kr/learn/courses/30/lessons/181928

class Solution {
    public int solution(int[] num_list) {
        String odd = ""; //홀수
        String even = "";
        int length = num_list.length;
        int answer = 0;
        for(int i=0; i<length; i++){
            if(num_list[i] % 2 == 0){
                even += num_list[i];
            }else{
                odd += num_list[i];
            }
        }
        answer = Integer.parseInt(even) + Integer.parseInt(odd);
        return answer;
    }
}

profile
컴퓨터가 이해하는 코드는 바보도 작성할 수 있다. 사람이 이해하도록 작성하는 프로그래머가 진정한 실력자다. -마틴 파울러

0개의 댓글