假設火車站的自動售票機只能接受10元,5元,1元的硬幣
請撰寫一個程式,算出購買票價137元的車票時,所需投入各種幣值硬幣最少的數量?

(題目都說137了,我也懶得用使用者輸入了XD)

public class ex4_3{
 public static void main(String[] argv){
  int i = 137;
  int a = 137/10;
  int b = a/5;
  int c = a%5;
  
  System.out.println("10元的需要"+a+"個");
  System.out.println("5元的需要"+b+"個");
  System.out.println("1元的需要"+c+"個");
 }
}
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 steven70101 的頭像
    steven70101

    老人家的舊書房

    steven70101 發表在 痞客邦 留言(0) 人氣()