Advertisement
cvet40

Coins

Feb 28th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. package Z_Exams06;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Coins {
  6. public static void main(String[] args) {
  7. Scanner scan = new Scanner(System.in);
  8. double sum = Double.parseDouble(scan.nextLine());
  9.  
  10. int leva = (int) sum;
  11. int coins = (int) (sum * 100) % 100;
  12.  
  13. int count1Lev = 0;
  14. int count2Leva = 0;
  15. int count50Coins = 0;
  16. int count20Coins = 0;
  17. int count10Coins = 0;
  18. int count5Coins = 0;
  19. int count2Coins = 0;
  20. int count1Coins = 0;
  21.  
  22.  
  23. if (leva % 2 == 0) {
  24. count2Leva = leva / 2;
  25. } else {
  26. count2Leva = (leva - 1) / 2;
  27. count1Lev = 1;
  28. }
  29.  
  30. while (coins >= 50) {
  31. count50Coins++;
  32. coins = coins - 50;
  33. }
  34. while (coins >= 20) {
  35. count20Coins++;
  36. coins = coins - count20Coins * 20;
  37.  
  38. }
  39. while (coins >= 10) {
  40. count10Coins++;
  41. coins = coins - count10Coins * 10;
  42. }
  43. while (coins >= 5) {
  44. count5Coins++;
  45. coins = coins - count5Coins * 5;
  46. }
  47. while (coins >= 2) {
  48. count2Coins++;
  49. coins = coins - count2Coins * 2;
  50. }
  51. while (coins >= 1) {
  52. count1Coins++;
  53. coins = coins - count1Coins;
  54. }
  55. System.out.println(count1Lev + count2Leva + count50Coins + count20Coins + count10Coins + count5Coins + count2Coins + count1Coins);
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement