From 4ab6d88005e8ff3d6980a33fdb6d03d780b0dd74 Mon Sep 17 00:00:00 2001 From: sobaman Date: Fri, 31 Mar 2023 20:33:17 +0900 Subject: [PATCH] =?UTF-8?q?[2023-03-30]=20=EB=B6=80=EC=A1=B1=ED=95=9C=20?= =?UTF-8?q?=EA=B8=88=EC=95=A1=20=EA=B3=84=EC=82=B0=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=EC=9E=85=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\202\260\355\225\230\352\270\260.java" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "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" 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