Advertisement
GabrielHr00

05. Coins

Feb 2nd, 2025
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package whileLoop_Exercise;
  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.         int coinsCount = 0;
  11.         //money = money * 100;
  12.         money *= 100;
  13.  
  14.         while (money > 0) {
  15.             if (money >= 200) {
  16.                 money -= 200;
  17.             } else if (money >= 100) {
  18.                 money -= 100;
  19.             } else if (money >= 50) {
  20.                 money -= 50;
  21.             } else if (money >= 20) {
  22.                 money -= 20;
  23.             } else if (money >= 10) {
  24.                 money -= 10;
  25.             } else if (money >= 5) {
  26.                 money -= 5;
  27.             } else if (money >= 2) {
  28.                 money -= 2;
  29.             } else if (money >= 1) {
  30.                 money -= 1;
  31.             } else {
  32.                 break;
  33.             }
  34.  
  35.             coinsCount++;
  36.         }
  37.  
  38.         System.out.print(coinsCount);
  39.  
  40.  
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement