SMALL
사용한 함수 : String.format
문제 조건에 소수점 이하 3자리까지 출력하기가 있다.
- 사용할 수 있는 함수는
1. Math.round
2. String.format
Math.round를 사용했을 때 소수점이 긴 경우 3자리로 잘라주지만 나눠떨어지는경우 표시해주지않는다.
-> String.format은 무조건 자리수를 모두 표시해주기때문에 이 함수를 사용했다.
더보기
result[i] = Math.round((double)count / num * 100 * 1000) / 1000.0;
더보기
for(int i = 0; i < size; i++) {
System.out.println(String.format("%.3f", result[i]) + "%");
}
SMALL
'기록 > 알고리즘' 카테고리의 다른 글
백준 10951) A + B - 4 (Java EOF) (0) | 2020.03.08 |
---|---|
백준 15552) 빠른 A + B (Buffered class) (0) | 2020.03.08 |
2019-2) Finding path in fantasia (0) | 2020.03.06 |
2019-2) Synchronizing Clocks (0) | 2020.03.06 |
2019-2) # of Changes (0) | 2020.03.06 |