JAVA STUDY/프로그래머스
프로그래머스 피자 나눠 먹기 (1) 문제
GreatJang
2023. 12. 11. 22:34
class Solution {
public int solution(int n) {
if(1<= n && n <=7) {
return 1;
}
return (int)Math.ceil((double) n/7);
}
}
// Math.ceil은 소수점 올림
&& : 자바 and 연산
Math.ceil() : Math 클래스의 Method, 소수점 뒤에 1이상의 숫자가 있으면 올린다.(올림)
(int)Math.ceil((double) n/7) : double 형변환 후 나눈 결과를 올림함수 사용하고 int로 값 받기