Advertisement
myrdok123

05. Coins

Mar 10th, 2024
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. package WhileLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Coins {
  6.  
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.  
  12.         double sum = Double.parseDouble(scanner.nextLine());
  13.  
  14.         double totalCoins = Math.floor(sum * 100);
  15.  
  16.         int countCoins = 0;
  17.  
  18.         while (totalCoins > 0 ){
  19.  
  20.             if(totalCoins >= 200){
  21.                 totalCoins -= 200;
  22.                 countCoins++;
  23.             } else if (totalCoins >= 100) {
  24.                 totalCoins -= 100;
  25.                 countCoins++;
  26.             }else if (totalCoins >= 50) {
  27.                 totalCoins -= 50;
  28.                 countCoins++;
  29.             }else if (totalCoins >= 20) {
  30.                 totalCoins -= 20;
  31.                 countCoins++;
  32.             }else if (totalCoins >= 10) {
  33.                 totalCoins -= 10;
  34.                 countCoins++;
  35.             }else if (totalCoins >= 5) {
  36.                 totalCoins -= 5;
  37.                 countCoins++;
  38.             }else if (totalCoins >= 2) {
  39.                 totalCoins -= 2;
  40.                 countCoins++;
  41.             }else if (totalCoins >= 1) {
  42.                 totalCoins -= 1;
  43.                 countCoins++;
  44.             }
  45.            
  46.         }
  47.  
  48.         System.out.println(countCoins);
  49.  
  50.  
  51.  
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement