프로그래머스 문제

두 수의 연산값 비교하기

nakgopsae 2024. 6. 12. 11:49


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

        String strA = Integer.toString(a);
        String strB = Integer.toString(b);

        String strAB = strA + strB;
        int resultAB = Integer.parseInt(strAB);
        int result2ab = 2*a*b;
        
        if (resultAB>result2ab){
            answer = resultAB;
        } else if (resultAB<result2ab) {
            answer = result2ab;
        }else if(resultAB == result2ab){
            answer = resultAB;
        }

        return answer;
    }// 문자열 변환후 a+b와 2*a*b를 비교하여 답안작성
}

 

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

n의 배수  (0) 2024.06.12
더 크게 합치기  (0) 2024.06.12
문자열 곱하기  (0) 2024.06.07
문자 리스트를 문자열로 변환하기  (0) 2024.06.07
문자열 섞기  (0) 2024.06.07