Advertisement
uktcar

05.2.05Coins

Apr 9th, 2021 (edited)
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ex05Coins {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double input = Double.parseDouble(scanner.nextLine());
  8.         input *= 100;
  9.  
  10.         int income = (int)input;
  11.         int coinCounter = 0;
  12.  
  13.         while (income > 0) {
  14.             if (income >= 200) {
  15.                 income -= 200;
  16.                 coinCounter++;
  17.             } else if (income >= 100) {
  18.                 income -= 100;
  19.                 coinCounter++;
  20.             } else if (income >= 50) {
  21.                 income -= 50;
  22.                 coinCounter++;
  23.             } else if (income >= 20) {
  24.                 income -= 20;
  25.                 coinCounter++;
  26.             } else if (income >= 10) {
  27.                 income -= 10;
  28.                 coinCounter++;
  29.             } else if (income >= 5) {
  30.                 income -= 5;
  31.                 coinCounter++;
  32.             } else if (income >= 2) {
  33.                 income -= 2;
  34.                 coinCounter++;
  35.             } else {
  36.                 income -= 1;
  37.                 coinCounter++;
  38.             }
  39.         }
  40.         System.out.println(coinCounter);
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement