Advertisement
Guest User

ex 6

a guest
Jan 28th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. Scanner in = new Scanner(System.in);
  9. int[] bnotes = new int[]{ 50, 20, 10, 5};
  10. int[] counter = new int[4];
  11. int amount;
  12. System.out.println("Enter amount:"); amount = in.nextInt();
  13. if(amount < 0)
  14. System.out.println("You cannot enter negative values!");
  15. if(amount < 5)
  16. System.out.println("You cannot withdraw less than 5 pounds.");
  17. if(amount > 250)
  18. System.out.println("You cannot withdraw more then 250 pounds.");
  19.  
  20. for (int i = 0; i < 4; i++) {
  21. if (amount >= bnotes[i]) {
  22. counter[i] = amount / bnotes[i];
  23. amount = amount - counter[i] * bnotes[i];
  24. }
  25. }
  26. for (int i = 0; i < 4; i++) {
  27. if (counter[i] != 0) {
  28. System.out.println("£"+bnotes[i] + ": " + counter[i]);
  29. }
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement