返回列表 發帖
本帖最後由 劉柏瓘 於 2020-8-20 10:28 編輯
  1. package A;
  2. import java.util.Scanner;
  3. public class A
  4. {
  5.     public static void main(String[] args)
  6.            {     
  7.                
  8.                 Scanner s=new Scanner(System.in);
  9.                 int a,b;
  10.                   System.out.println("***智慧找零系統***");
  11.                   System.out.print("請輸入商品價格:");
  12.                   a=s.nextInt();
  13.                   System.out.print("客人付了多少錢:");
  14.                   b=s.nextInt();
  15.                   System.out.println("需找客人"+(b-a)+"元");
  16.                   System.out.println();
  17.                   
  18.                   if((b-a)>=500)
  19.                           System.out.println("五百元鈔票"+(b-a)/500+"張");
  20.                   if((b-a)%500>=100)
  21.                           System.out.println("一百元鈔票"+((b-a)%500)/100+"張");
  22.                   if((((b-a)%500)%100)>=50)
  23.                           System.out.println("五十元硬幣"+(((b-a)%500)%100)/50+"枚");
  24.                   if((((b-a)%500)%100)%50>=10)
  25.                           System.out.println("十元硬幣"+(((b-a)%500)%100)%50/10+"枚");
  26.                   if((((((b-a)%500)%100)%50)%10)>=5)
  27.                           System.out.println("五元硬幣"+((((((b-a)%500)%100)%50)%10)/5)+"枚");
  28.                   if((((b-a)%500)%100)%50%10%5>=1)
  29.                           System.out.println("一元硬幣"+(((b-a)%500)%100)%50%10+"枚");       
  30.                   
  31.     }
  32. }
複製代碼

TOP

返回列表