Skip to content

Instantly share code, notes, and snippets.

@Exom9434
Created May 16, 2024 11:26
Show Gist options
  • Save Exom9434/b879ddf021e846853985a5762ab1ffaa to your computer and use it in GitHub Desktop.
Save Exom9434/b879ddf021e846853985a5762ab1ffaa to your computer and use it in GitHub Desktop.
//노재경
import java.util.Scanner;
public class Main{
public static void main(String[] args){
boolean flag = true;
Scanner scanner = new Scanner(System.in);
int price = 0;
int cashback = 0;
int cashbackRounded = 0;
while(flag){
System.out.println("[캐시백 계산]");
System.out.print("숫자를 입력하세요. (금액): ");
if(scanner.hasNextInt()){
price = scanner.nextInt();
scanner.nextLine();
cashback = 0;
cashbackRounded = 0;
if(price >=1000){
cashback = (int) (price * 0.1);
cashbackRounded = Math.round(cashback/100) * 100;
if(cashbackRounded > 300){
cashbackRounded = 300;
}
}
String result = String.format("결제 금액은 %d원이고, 캐시백은 %d원 입니다.\t", price, cashbackRounded);
System.out.println(result);
} else {
String input = scanner.nextLine();
System.out.println(input);
if (input.equals("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