Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int[] bnotes = new int[]{ 50, 20, 10, 5};
- int[] counter = new int[4];
- int amount;
- System.out.println("Enter amount:"); amount = in.nextInt();
- if(amount < 0)
- System.out.println("You cannot enter negative values!");
- if(amount < 5)
- System.out.println("You cannot withdraw less than 5 pounds.");
- if(amount > 250)
- System.out.println("You cannot withdraw more then 250 pounds.");
- for (int i = 0; i < 4; i++) {
- if (amount >= bnotes[i]) {
- counter[i] = amount / bnotes[i];
- amount = amount - counter[i] * bnotes[i];
- }
- }
- for (int i = 0; i < 4; i++) {
- if (counter[i] != 0) {
- System.out.println("£"+bnotes[i] + ": " + counter[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement