Java/Do it
거스름돈 구하기_2
yedevlife
2020. 4. 19. 23:15
키보드로 원하는 커피의 값과 투입하려는 금액을 입력하고 거스름돈 구하기.
import java.util.Scanner;
public class Problem04_03 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int coffee, money, change;
System.out.print("얼마짜리 커피를 드시겠어요? ==>");
coffee=s.nextInt();
System.out.print("금액을 투입해주세요. ==>");
money=s.nextInt();
change=money-coffee;
System.out.printf("거스름 돈은 %d원 입니다.",change);
int c500,c100,c50;
c500=change/500;
change=change%500;
c100=change/100;
change=change%100;
c50=change/50;
change=change%50;
System.out.println();
System.out.printf("500원 짜리 %d개\n",c500);
System.out.printf("100원 짜리 %d개\n",c100);
System.out.printf("50원 짜리 %d개\n",c50);
}
}