Last active
August 2, 2023 01:04
-
-
Save kingseungil/dc105bd78d9bdb8f8a41f1e8c4d1a510 to your computer and use it in GitHub Desktop.
Zerobase-miniproject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Miniproject2 { | |
public static void main(String[] args) { | |
System.out.println("[캐시백 계산]"); | |
try (Scanner sc = new Scanner(System.in)) { // try-with-resources 문으로 Scanner 객체 자동 닫기 | |
System.out.print("결제 금액을 입력해 주세요. (금액):"); | |
int price = sc.nextInt(); | |
int cashback = price / 10; | |
// 100원 미만은 캐시백이 발생하지 않습니다. | |
if (cashback < 100) { | |
cashback = 0; | |
} else { | |
// switch 문으로 캐시백 금액 계산 | |
cashback = switch (cashback / 100) { | |
case 1 -> 100; | |
case 2 -> 200; | |
default -> 300; | |
}; | |
} | |
// 삼항 연산자로 결제 금액과 캐시백 금액 출력 | |
System.out.print("결제 금액은 " + price + "원이고, 캐시백은 " + cashback + "원 입니다."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment