Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.ArrayList;
- public class CoinsDenominations{
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int deno[] = {1, 2, 5, 10, 20, 50};
- int count = 0;
- //int index = 0;
- ArrayList <Integer> result = new ArrayList<Integer>();
- int sum = scan.nextInt();
- for (int i = deno.length - 1; i >= 0; i--) {
- while(deno[i] <= sum){
- sum = sum - deno[i];
- result.add(deno[i]);
- count++;
- }
- }
- if(sum == 0){
- System.out.println("Youn need " + count + " coins.");
- System.out.println(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement