부족한 금액 계산하기

han.user();·2023년 4월 16일
0

프로그래머스

목록 보기
75/87
post-thumbnail

public class InsufficientAmount {
    public static void main(String[] args) {
        int price = 3;
        int money = 20; // 초기돈
        int count = 4;

        long answer = 0; //부족한 돈
        int time = 0; //탄 횟수 카운트

        answer = (long) money;

        while (time < count) {
            time++;
            answer -= price * time;
        }
        if (answer < 0) {
            System.out.println(Math.abs(answer));
        } else {
            System.out.println(0);
        }
    }
}
profile
I'm still hungry.

0개의 댓글