返回列表 發帖
  1. import java.util.Scanner;
  2. public class Smart
  3. {

  4.         public static void main(String[] args)
  5.         {
  6.                 Scanner s=new Scanner(System.in);
  7.                 int a;
  8.                 int b;
  9.                 int fh,oh,f,t,o;
  10.                 int x;
  11.                 System.out.println("***智慧找零系統***");
  12.                 System.out.print("請輸入商品價格:");
  13.                 b=s.nextInt();
  14.                 System.out.print("客人付了多少錢?");
  15.                 a=s.nextInt();
  16.                 x=a-b;
  17.             fh=(a-b)/500;
  18.             System.out.println("五百元鈔票"+fh+"張");
  19.             oh=(a-b-fh*500)/100;
  20.             System.out.println("一百元鈔票"+oh+"張");
  21.             f=(a-b-fh*500-oh*100)/50;
  22.             System.out.println("五十元硬幣"+f+"枚");
  23.             t=(a-b-fh*500-oh*100-f*50)/10;
  24.             System.out.println("十元硬幣"+t+"枚");
  25.             o=(a-b-fh*500-oh*100-f*50-t*10);
  26.             System.out.println("一元硬幣"+o+"枚");
  27.             
  28.                
  29.                
  30.             

  31.         }

  32. }
複製代碼

TOP

返回列表