- import java.util.Scanner;
- public class Smart
- {
- public static void main(String[] args)
- {
- Scanner s=new Scanner(System.in);
- int a;
- int b;
- int fh,oh,f,t,o;
- int x;
- System.out.println("***智慧找零系統***");
- System.out.print("請輸入商品價格:");
- b=s.nextInt();
- System.out.print("客人付了多少錢?");
- a=s.nextInt();
- x=a-b;
- fh=(a-b)/500;
- System.out.println("五百元鈔票"+fh+"張");
- oh=(a-b-fh*500)/100;
- System.out.println("一百元鈔票"+oh+"張");
- f=(a-b-fh*500-oh*100)/50;
- System.out.println("五十元硬幣"+f+"枚");
- t=(a-b-fh*500-oh*100-f*50)/10;
- System.out.println("十元硬幣"+t+"枚");
- o=(a-b-fh*500-oh*100-f*50-t*10);
- System.out.println("一元硬幣"+o+"枚");
-
-
-
-
- }
- }
複製代碼 |