Skip to content

Instantly share code, notes, and snippets.

@FeelingXD
Last active January 5, 2023 14:09
Show Gist options
  • Save FeelingXD/e43c140ed43e65af7730a15076ff2568 to your computer and use it in GitHub Desktop.
Save FeelingXD/e43c140ed43e65af7730a15076ff2568 to your computer and use it in GitHub Desktop.
캐쉬백 프로그램
/*
작성자: 고지민
*/
//cashback
//code with oracle openjdk 1.8
import java.util.*;
public class Main {
public static void main(String[] args) {
System.out.println("[캐시백 계산]");
Scanner input= new Scanner(System.in);
int pay= checkInt("결제 금액을 입력해 주세요.(금액):",input,0);
int cashback_percent=10;
int cashback=(pay*cashback_percent/100)/100*100;
System.out.printf("결제 금액은 %d원이고, 캐시백은 %d원 입니다. ",pay,Math.min(300,cashback));
}
public static int checkInt(String message,Scanner input,int min){
try {
System.out.print(message);
int value = input.nextInt();
if (value<min){
throw new Exception();
}
return value;
}
catch (Exception e){
System.out.println("다시 입력해주세요");
return checkInt(message,input,min);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment