Advertisement
Guest User

Untitled

a guest
Aug 6th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. package coins;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Coins {
  6.    
  7.     public static void main(String[] args) {
  8.        
  9.         Scanner scanner = new Scanner(System.in);
  10.         double input = Double.parseDouble(scanner.nextLine());
  11.         int change = (int) (input * 100);
  12.        
  13.         int counter = 0;
  14.         while (change > 0)
  15.         {
  16.             if (change >= 200) { counter += 1; change -= 200; }
  17.             else if (change >= 100) { counter += 1; change -= 100; }
  18.             else if (change >= 50) { counter += 1; change -= 50; }
  19.             else if (change >= 40) { counter += 2; change -= 40; }
  20.             else if (change >= 20) { counter += 1; change -= 20; }
  21.             else if (change >= 10) { counter += 1; change -= 10; }
  22.             else if (change >= 5) { counter += 1; change -= 5; }
  23.             else if (change >= 4) { counter += 2; change -= 4; }
  24.             else if (change >= 2) { counter += 1; change -= 2; }
  25.             else if (change >= 1) { counter += 1; change -= 1; }
  26.         }
  27.         System.out.println(counter);
  28.     }  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement