アットウィキロゴ

ouchi > Practice > Study04-02

  1. import java.util.Scanner;
  2.  
  3. /** 金種判定を行う */
  4. public class Study04_2 {
  5.  
  6. public static void main(String[] args) {
  7.  
  8. int[] yen = {10000, 5000, 1000, 500, 100, 50, 10, 5, 1};
  9. // int[] yen = {10000, 5000, 2000, 1000, 500, 100, 50, 10, 5, 1};
  10.  
  11. Scanner scan = new Scanner(System.in);
  12.  
  13. // 入力
  14. int input;
  15. System.out.println("任意の金額を入力してください");
  16. input = scan.nextInt();
  17.  
  18. int tmp = input;
  19. int[] result = new int[yen.length];
  20. for (int i = 0; i < yen.length; i++) {
  21. result[i] = tmp / yen[i];
  22. tmp -= yen[i] * result[i];
  23. }
  24.  
  25. for (int i = 0; i < yen.length; i++) {
  26. System.out.println(yen[i] + "円 : " + result[i] + "枚");
  27. }
  28.  
  29. }
  30.  
  31. }
  32.  
最終更新:2013年05月15日 18:11