코딩테스트/lv0

[프로그래머스 코딩테스트] java Lv.0 주사위 게임2

chantleman 2024. 10. 17. 19:33

import java.lang.Math;
class Solution {
    public int solution(int a, int b, int c) {
        int answer = 0;
        if(a!=b && b!=c && a!=c){
            answer=a+b+c;
        }
        else if(a==b&& b==c&& a==c){
            answer = (a+b+c)*(int)(Math.pow(a,2)+Math.pow(b,2)+Math.pow(c,2))*(int)(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3));
        }
        else{
            answer = (a+b+c)*(int)(Math.pow(a,2)+Math.pow(b,2)+Math.pow(c,2));
        }
        
        return answer;
    }
}

 

 

Math.pow는 double을 return하기 때문에 int로 downcasting해줘야합니당