Advertisement
GabrielHr00

Coins

Nov 27th, 2022
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. package S5_WhileLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Coins {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. double change = Double.parseDouble(scanner.nextLine());
  9.  
  10. // convert change only in stotinki
  11. double changeInSt = change * 100;
  12. // save count of coins
  13. int stotinkiCount = 0;
  14.  
  15. // iterate until we return the change
  16. while (changeInSt > 0) {
  17. // return 2 lv = 200 st.
  18. if(changeInSt >= 200) {
  19. changeInSt = changeInSt - 200;
  20. }
  21. // return 1 lv = 100 st.
  22. else if(changeInSt >= 100) {
  23. changeInSt = changeInSt - 100;
  24. }
  25. // return 50 st.
  26. else if(changeInSt >= 50) {
  27. changeInSt = changeInSt - 50;
  28. }
  29. // return 20 st.
  30. else if(changeInSt >= 20) {
  31. changeInSt = changeInSt - 20;
  32. }
  33. // return 10 st.
  34. else if(changeInSt >= 10) {
  35. changeInSt = changeInSt - 10;
  36. }
  37. // return 5 st.
  38. else if(changeInSt >= 5) {
  39. changeInSt = changeInSt - 5;
  40. }
  41. // return 2 st.
  42. else if(changeInSt >= 2) {
  43. changeInSt = changeInSt - 2;
  44. }
  45. // return 1 st.
  46. else if(changeInSt >= 1) {
  47. changeInSt = changeInSt - 1;
  48. }
  49. // for stotinki < 0 (floating number error)
  50. else {
  51. break;
  52. }
  53.  
  54. stotinkiCount++;
  55. }
  56.  
  57. System.out.println(stotinkiCount);
  58.  
  59.  
  60. }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement