문제
풀이
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 전기 사용량
int num = sc.nextInt();
// 누진세
double price = 0;
if(num < 100) {
price = (num * 0.5)/100;
} else if(num < 200) {
price = (num * 0.7)/100;
} else if(num < 300) {
price = (num * 0.9)/100;
} else {
price = num/100;
}
DecimalFormat df = new DecimalFormat("0.00");
String result = df.format(price);
System.out.print(result);
}
}
System.out.print(Double.parseDouble(String.format("%.2f",price))); 을 사용할 수 있었지만 첫 번째 테스트케이스에 통과하지 않았다. 그래서 DecimalFormat을 사용했다.
'코딩테스트' 카테고리의 다른 글
[구름LEVEL] 삼각형의 넓이 (0) | 2021.03.12 |
---|---|
[구름LEVEL] 공백 없애기 (0) | 2021.03.12 |
[프로그래머스] 완주하지 못한 선수 (0) | 2020.04.09 |
[프로그래머스] 모의고사 (0) | 2020.04.09 |