Advertisement
Vasilena

ТЕМА 07

Dec 3rd, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3.  
  4. public class CoinsDenominations{
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.         int deno[] = {1, 2, 5, 10, 20, 50};
  8.         int count = 0;
  9.         //int index = 0;
  10.         ArrayList <Integer> result = new ArrayList<Integer>();
  11.         int sum = scan.nextInt();
  12.  
  13.         for (int i = deno.length - 1; i >= 0; i--) {
  14.             while(deno[i] <= sum){
  15.                 sum = sum - deno[i];
  16.                 result.add(deno[i]);
  17.                 count++;
  18.             }
  19.         }
  20.         if(sum == 0){
  21.             System.out.println("Youn need " + count + " coins.");
  22.             System.out.println(result);
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement