class Solution {
public int solution(int price) {
int answer = 0;
if(price>=500000) return (int)(price*0.8);
if(price>=300000) return (int)(price*0.9);
if(price>=100000) return (int)(price*0.95);
return price;
}
}
▶int형에 소수점을 곱하는 경우 타입이 double타입이 된다.
▶이러한 경우 문제에서 요구하는 int형이기 때문에 double을 int형으로 강제적 형변환을 해준다.
'프로그래머스(자바) > LV.0(자바)' 카테고리의 다른 글
역삼각형 출력하기-★별찍기 (0) | 2022.11.24 |
---|---|
모음제거 → String 클래스 →contains(), replaceAll()★ + 정규식★ (0) | 2022.11.22 |
제곱수 판별하기 -Math.sqrt() (0) | 2022.11.22 |
자릿수 더하기★ →n값 갱신 + 10으로 나눈 나머지(각 자리수) (0) | 2022.11.22 |
배열의 유사도★ →equals(), contains() ←List<String> ★★ (0) | 2022.11.22 |