알고리즘/기타
[프로그래머스] 옷가게 할인 받기 - Java
jny0
2023. 3. 6. 11:50
https://school.programmers.co.kr/learn/courses/30/lessons/120818
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제 상황
머쓱이네 옷가게는 10만 원 이상 사면 5%, 30만 원 이상 사면 10%, 50만 원 이상 사면 20%를 할인해줍니다.
구매한 옷의 가격 price가 주어질 때, 지불해야 할 금액을 return 하도록 solution 함수를 완성해보세요.
문제 풀이
class Solution {
public int solution(int price) {
int answer = 0;
double result ;
if(price>=500000) result = price*0.8;
else if(price>=300000) result = price*0.9;
else if(price>=100000) result = price*0.95;
else result = price;
answer = (int)result;
return answer;
}
}