ledkaa

Calculate Change

Mar 11th, 2023
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Calculate_Change {
  4. public static void main(String[] args) {
  5. Scanner sc=new Scanner(System.in);
  6. double bill=sc.nextDouble();
  7. double pay=sc.nextDouble();
  8.  
  9. int counterLev=0;
  10. int counterFifty=0;
  11. int counterTwenty=0;
  12. int counterTen=0;
  13. int counterFive=0;
  14. int counterTwo=0;
  15. int counterOne=0;
  16.  
  17.  
  18. double change=(pay-bill)*100;
  19.  
  20. while(change>0){
  21. if(change>=100)
  22. {
  23. change-=100;
  24. counterLev++;
  25. }
  26. else if(change>=50){
  27. change-=50;
  28. counterFifty++;
  29. }
  30. else if (change>=20){
  31. change-=20;
  32. counterTwenty++;
  33. }
  34. else if(change>=10)
  35. {
  36. change-=10;
  37. counterTen++;
  38. }
  39. else if(change>=5)
  40. {
  41. change-=5;
  42. counterFive++;
  43. }
  44. else if(change>=2)
  45. {
  46. change-=2;
  47. counterTwo++;
  48. }
  49. else if(change>=1){
  50. change-=1;
  51. counterOne++;
  52. }
  53.  
  54. }
  55. if(counterLev>1){
  56. System.out.printf("%d x 1 lev %n",counterLev);
  57. }
  58. if(counterFifty>0){
  59. System.out.printf("%d x 50 stotinki %n",counterFifty);
  60. }
  61. if(counterTwenty>0){
  62. System.out.printf("%d x 20 stotinki %n",counterTwenty);
  63. }
  64. if(counterTen>0){
  65. System.out.printf("%d x 10 stotinki %n",counterTen);
  66. }
  67. if(counterFive>0){
  68. System.out.printf("%d x 5 stotinki %n",counterFive);
  69. }
  70. if(counterTwo>0){
  71. System.out.printf("%d x 2 stotinki %n",counterTwo);
  72. }
  73. if(counterOne>1){
  74. System.out.printf("%d x 1 stotinki %n",counterOne);
  75. }
  76. else if(counterOne==1){
  77. System.out.printf("%d x 1 stotinka",counterOne);
  78. }
  79. }
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment