Created
January 12, 2025 13:20
-
-
Save Exom9434/3160cab5cc38f246fccbada9ebc2673f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Main { | |
public static void main(String[] args) { | |
boolean flag = true; | |
Scanner scanner = new Scanner(System.in); | |
while (flag) { | |
System.out.println("[캐시백 계산]"); | |
System.out.print("숫자를 입력하세요. (금액): "); | |
if (scanner.hasNextInt()) { | |
int price = scanner.nextInt(); | |
scanner.nextLine(); | |
int cashbackRounded = 0; | |
if (price >= 1000) { | |
cashbackRounded = Math.round((price * 0.1f) / 100.0f) * 100; | |
cashbackRounded = Math.min(cashbackRounded, 300); // 최대 300원 제한 | |
} | |
System.out.printf("결제 금액은 %d원이고, 캐시백은 %d원 입니다.\n", price, cashbackRounded); | |
} else { | |
String input = scanner.nextLine(); | |
if (input.equalsIgnoreCase("stop")) { | |
System.out.println("시스템을 종료합니다."); | |
flag = false; | |
} else { | |
System.out.println("정수만 입력해주세요."); | |
} | |
} | |
} | |
scanner.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment