Advertisement
desislava_topuzakova

06.Coins

Mar 11th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. package TestJan;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.text.DecimalFormatSymbols;
  5. import java.util.Locale;
  6. import java.util.Scanner;
  7.  
  8. public class Coins {
  9. public static void main(String[] args) {
  10.  
  11. Scanner scan = new Scanner(System.in);
  12. DecimalFormat dm = new DecimalFormat("#0.00");
  13. dm.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.CANADA));
  14.  
  15.  
  16. double change = Double.parseDouble(scan.nextLine());
  17. double sum = 0.0;
  18. int coinsCounter = 0;
  19.  
  20.  
  21. while (Double.parseDouble(dm.format(sum + 2.0)) <= change) {
  22. sum += 2.0;
  23. coinsCounter++;
  24. }
  25.  
  26. while (Double.parseDouble(dm.format(sum + 1.0)) <= change) {
  27. sum += 1.0;
  28. coinsCounter++;
  29. }
  30.  
  31. while (Double.parseDouble(dm.format(sum + 0.5)) <= change) {
  32. sum += 0.5;
  33. coinsCounter++;
  34. }
  35.  
  36.  
  37. while (Double.parseDouble(dm.format(sum + 0.2)) <= change) {
  38. sum += 0.2;
  39. coinsCounter++;
  40. }
  41.  
  42. while (Double.parseDouble(dm.format(sum + 0.1)) <= change) {
  43. sum += 0.1;
  44. coinsCounter++;
  45. }
  46.  
  47. while (Double.parseDouble(dm.format(sum + 0.05)) <= change) {
  48. sum += 0.05;
  49. coinsCounter++;
  50. }
  51.  
  52. while (Double.parseDouble(dm.format(sum + 0.02)) <= change) {
  53. sum += 0.02;
  54. coinsCounter++;
  55. }
  56.  
  57. while (Double.parseDouble(dm.format(sum + 0.01)) <= change) {
  58. sum += 0.01;
  59. coinsCounter++;
  60.  
  61. System.out.println(coinsCounter);
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement