diff --git "a/soba/mar/2023-03-30-\353\266\200\354\241\261\355\225\234\352\270\210\354\225\241\352\263\204\354\202\260\355\225\230\352\270\260.java" "b/soba/mar/2023-03-30-\353\266\200\354\241\261\355\225\234\352\270\210\354\225\241\352\263\204\354\202\260\355\225\230\352\270\260.java" new file mode 100644 index 0000000..2770b2a --- /dev/null +++ "b/soba/mar/2023-03-30-\353\266\200\354\241\261\355\225\234\352\270\210\354\225\241\352\263\204\354\202\260\355\225\230\352\270\260.java" @@ -0,0 +1,19 @@ +package mar; + +//return : (price + price * 2 + price *3 ... + price * n) - money +// but return이 음수면 0 출력 +// long말고 int로 선언하면 에러남 + +class 부족한금액계산하기 { + public long solution(int price, int money, int count) { + long answer = -1; + long total = 0; + + for(int i = 1; i <= count; i++){ + total += price * i; + } + answer = total - money; + + return answer = (answer < 0) ? 0 : answer; + } +} \ No newline at end of file