프로그래머스 코딩 테스트 12. 저축
1. 문제 설명 - 빈칸 채우기

제한 사항

2. 입출력 예시


3. 코드 작성
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int start = sc.nextInt();
int before = sc.nextInt();
int after = sc.nextInt();
int money = start;
int month = 1;
while (money < 70) {
money += before;
month++;
}
while (money < 100) {
money += after;
month++;
}
System.out.println(month);
}
}
- 100만원을 모을 때 까지의 조건을 살펴봐야 함
- 70만원 이전까진 매달 before만큼 저금
- while (money < 70) { money += before; month++; }
- 70만원을 넘긴 후 100만원까지는 매달 after만큼 저금
- while (money < 100) { money += after; month++; }
4. 테스트 실행

5. 제출 후 채점

Share article