프로그래머스 문제

더 크게 합치기

nakgopsae 2024. 6. 12. 11:22


class Solution {
    public int solution(int a, int b) {
        int answer = 0;

        String aToString = Integer.toString(a);
        String bToString = Integer.toString(b);
        // 문자로 바꿈

        String ab = aToString + bToString;
        String ba = bToString + aToString;
        
        // 문자끼리 더함

        int resultAB = Integer.parseInt(ab);
        int resultBA = Integer.parseInt(ba);
        
        //다시 숫자로 바꿈

        if (resultAB>resultBA){
            answer = resultAB;
            //ab가 더 크다
        } else if (resultBA> resultAB) {
            answer = resultBA;
            // ab가 더 작다
        } else if (resultAB == resultBA) {
            answer = resultAB;
            
            //둘 다 값이 동일 
        }

        return answer;
        
    }
}

 

다른 사람 풀이 보면 한번에 묶어서 하시던데 

 

난 안돼 

 

자바도 익숙해지면 되겄지 뭐

'프로그래머스 문제' 카테고리의 다른 글

n의 배수  (0) 2024.06.12
두 수의 연산값 비교하기  (0) 2024.06.12
문자열 곱하기  (0) 2024.06.07
문자 리스트를 문자열로 변환하기  (0) 2024.06.07
문자열 섞기  (0) 2024.06.07