返回列表 發帖
  1. import java.util.Scanner;
  2. public class A {
  3.         public static void main(String args[])
  4.         {
  5.                 Scanner s=new Scanner(System.in);
  6.                 int a,b,c=0,d=0;
  7.                 System.out.println("***智慧找零系統***"+"\n");
  8.                
  9.                 System.out.print("請輸入商品價格: ");
  10.                 a=s.nextInt();
  11.                
  12.                 System.out.print("客人付了多少錢:");
  13.                 b=s.nextInt();
  14.                
  15.                 c=b-a;
  16.                 System.out.print("需找客人"+c+"元");
  17.                
  18.                 if (c>=500)
  19.                 {
  20.                         System.out.println("500元鈔票"+c/500+"張");
  21.                         c=c%500;
  22.                 }
  23.                 if (c>=100)
  24.                 {
  25.                         System.out.println("100元鈔票"+c/100+"張");
  26.                         c=c%100;
  27.                 }
  28.                 if (c>=50)
  29.                 {
  30.                         System.out.println("50元硬幣"+c/50+"個");
  31.                         c=c%50;
  32.                 }
  33.                 if (c>=10)
  34.                 {
  35.                         System.out.println("10元硬幣"+c/10+"個");
  36.                         c=c%10;
  37.                 }
  38.                 if (c>=5)
  39.                 {
  40.                         System.out.println("5元硬幣"+c/5+"個");
  41.                         c=c%5;
  42.                 }
  43.                 if (c>=1)
  44.                 {
  45.                         System.out.println("1元硬幣"+c/1+"個");
  46.                         c=c%1;
  47.                 }
  48.                
  49.                 System.out.println("請領取找回的錢");
  50.                
  51.         }

  52. }
複製代碼

TOP

返回列表