Advertisement
GabrielHr00

05. Coins

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