프로그래머스/lv0
피자 나눠 먹기 (1)
do_it0904
2022. 12. 5. 10:17
/* 피자 나눠 먹기 (1)
* 피자를 일곱 조각으로 잘라 줍니다.
* 피자를 나눠먹을 사람의 수 n이 주어질 때,
* 모든 사람이 피자를 한 조각 이상 먹기 위해 필요한 피자의 수를 return
*
* n result
* 7 1
* 1 1
* 15 3
*/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | public class programmer_0_39 { static int a1 = 7; static int a2 = 1; static int a3 = 15; public int solution(int n) { // 다른 사람 풀이 // int answer = (n%7==0) ? n/7 : n/7 + 1; int answer = 0; //while문은 조건이 false 될때까지 실행(참일때 내부 실행) while((answer * 7 / n) == 0){ System.out.println(answer + " / " + ((answer * 7 / n) == 0)); answer++; } return answer; } public static void main(String args[]){ programmer_0_39 t = new programmer_0_39(); System.out.println("---------------------------------------"); System.out.println("result = " + t.solution(a1)); System.out.println("---------------------------------------"); System.out.println("result2 = " + t.solution(a2)); System.out.println("---------------------------------------");; System.out.println("result2 = " + t.solution(a3)); System.out.println("---------------------------------------"); } } | cs |