-
프로그래머스 - 부족한 금액 계산하기 [자바]Algorithms/- 프로그래머스 2022. 2. 1. 02:13
- 문제 링크 : 부족한 금액 계산하기
정답
class Solution { public long solution(int price, int money, int count) { long answer = 0L; /* price 이용료 n 배 count 번 모자른 금액 return But 부족하지 않으면 0 return */ long total = 0L; for(int i=1; i<=count; i++){ total += price * i; } answer = total - money; if(answer < 0){ return 0; } return answer; } }
분석
- 단순한 사칙연산
- long 자료형을 알고 있는지 단순히 묻는 문제
반응형