- import java.util.Scanner;
- public class A {
- public static void main(String args[])
- {
- Scanner s=new Scanner(System.in);
- int a,b,c=0,d=0;
- System.out.println("***智慧找零系統***"+"\n");
-
- System.out.print("請輸入商品價格: ");
- a=s.nextInt();
-
- System.out.print("客人付了多少錢:");
- b=s.nextInt();
-
- c=b-a;
- System.out.print("需找客人"+c+"元");
-
- if (c>=500)
- {
- System.out.println("500元鈔票"+c/500+"張");
- c=c%500;
- }
- if (c>=100)
- {
- System.out.println("100元鈔票"+c/100+"張");
- c=c%100;
- }
- if (c>=50)
- {
- System.out.println("50元硬幣"+c/50+"個");
- c=c%50;
- }
- if (c>=10)
- {
- System.out.println("10元硬幣"+c/10+"個");
- c=c%10;
- }
- if (c>=5)
- {
- System.out.println("5元硬幣"+c/5+"個");
- c=c%5;
- }
- if (c>=1)
- {
- System.out.println("1元硬幣"+c/1+"個");
- c=c%1;
- }
-
- System.out.println("請領取找回的錢");
-
- }
- }
複製代碼 |