알고리즘 풀이 방법입니다.
문제(Problem) -> 생각(Think) -> 해결책(Solution) -> 리뷰(Review) 를 통해서 정리해서 작성합니다.
Problem📄

https://school.programmers.co.kr/learn/courses/30/lessons/132267

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr


Think🤔

문제에서 말하는 대로 받은 코카 콜라의 갯수를 세어주는 문제


Solution✍
public class Coke {
    public static void main(String[] args) {
        int a = 3;
        int b = 1;
        int n = 20;
        int recCoke = 0;
        int answer = 0; // 9

        while(n >= a){
            recCoke = n / a * b; // 받은 코카
            n = n - ( n - n % a ) + (recCoke);
            answer += recCoke;
        }
        System.out.println(answer);

    }
}

Review🤩

어렵지 않음!


 

+ Recent posts