Advertisement
Guest User

Untitled

a guest
Aug 6th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 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 scale = Math.pow(10, 2);
  11.         double change = Double.parseDouble(scanner.nextLine());
  12.        
  13.         int counter = 0;
  14.         while (change > 0)
  15.         {
  16.             if (change >= 2) { counter += 1; change -= 2; }
  17.             else if (change >= 1) { counter += 1; change -= 1; }
  18.             else if (change >= 0.50) { counter += 1; change -= 0.50; }
  19.             else if (change >= 0.40) { counter += 2; change -= 0.40; }
  20.             else if (change >= 0.20) { counter += 1; change -= 0.20; }
  21.             else if (change >= 0.10) { counter += 1; change -= 0.10; }
  22.             else if (change >= 0.05) { counter += 1; change -= 0.05; }
  23.             else if (change >= 0.04) { counter += 2; change -= 0.04; }
  24.             else if (change >= 0.02) { counter += 1; change -= 0.02; }
  25.             else if (change >= 0.01) { counter += 1; change -= 0.01; }
  26.             change =  Math.round(change * scale) / scale;
  27.         }
  28.         System.out.println(counter);
  29.     }
  30.    
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement