-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution7.java
More file actions
28 lines (25 loc) · 1.14 KB
/
Solution7.java
File metadata and controls
28 lines (25 loc) · 1.14 KB
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
/* 코딩 테스트 공부 - 7
* 새로 생긴 놀이기구는 인기가 매우 많아 줄이 끊이질 않습니다. 이 놀이기구의 원래 이용료는 price원 인데, 놀이기구를 N 번 째 이용한다면 원래 이용료의 N배를 받기로 하였습니다.
* 즉, 처음 이용료가 100이었다면 2번째에는 200, 3번째에는 300으로 요금이 인상됩니다.
* 놀이기구를 count번 타게 되면 현재 자신이 가지고 있는 금액에서 얼마가 모자라는지를 return 하도록 solution 함수를 완성하세요. 단, 금액이 부족하지 않으면 0을 return 하세요.
*/
package codingTest;
public class Solution7 {
public static long solution(int price, int money, int count) {
long answer = 0;
long upmoney = 0;
for(int i = 1; i <= count; i++){
upmoney += price * i;
}
answer = upmoney - money;
if(answer <= 0){
return 0;
}
else{
return answer;
}
}
public static void main(String[] args) {
System.out.println(solution(3, 20, 4));
}
}