本帖最後由 郭泰麟 於 2020-8-20 10:20 編輯
- import java.util.Scanner;
- public class b
- {
- public static void main(String args[])
- {
- Scanner s=new Scanner(System.in);
- int x,y,a,b,c,d,e;
- System.out.println("請輸入商品價格");
- y=s.nextInt();
- System.out.println("客人付了多少錢");
- x=s.nextInt();
- if(x>=y)
- {
- a=(x-y)/500;
- b=((x-y)-a*500)/100;
- c=((x-y)-a*500-b*100)/50;
- d=((x-y)-a*500-b*100-c*50)/10;
- e=(x-y)-a*500-b*100-c*50-d*10;
- System.out.println("須找客人"+(x-y)+"元");
- System.out.println("500元鈔票"+a+"張");
- System.out.println("100元鈔票"+b+"張");
- System.out.println("50元硬幣"+c+"枚");
- System.out.println("10元硬幣"+d+"枚");
- System.out.println("1元硬幣"+e+"枚");
- }
- else
- System.out.println("錢不夠");
- }
- }
複製代碼 |