옷가게 할인 받기

반즈·2023년 11월 27일

프로그래머스 입문

목록 보기
18/51

문제 설명

머쓱이네 옷가게는 10만 원 이상 사면 5%, 30만 원 이상 사면 10%, 50만 원 이상 사면 20%를 할인해줍니다.
구매한 옷의 가격 price가 주어질 때, 지불해야 할 금액을 return 하도록 solution 함수를 완성해보세요.

입출력 예


자바

나의 풀이

class Solution {
    public int solution(int price) {
        int answer = 0;
        if(price >= 500000){
            answer = (int)Math.floor(price - (price * 0.2));
        } else if (price >= 300000){
            answer = (int)Math.floor(price - (price * 0.1));
        } else if (price >= 100000){
            answer = (int)Math.floor(price - (price * 0.05));
        } else answer = price;
        return answer;
    }
}

자바스크립트

나의 풀이

function solution(price) {
    var answer = 0;
    if(price >= 500000){
        answer = Math.floor(price - (price * 0.2));
    } else if(price >= 300000){
        answer = Math.floor(price - (price * 0.1));
    } else if(price >= 100000){
        answer = Math.floor(price - (price * 0.05));
    } else {
        answer = price;
    }
    return answer;
}
profile
나를 채우다

0개의 댓글