Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class coins {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.println("Въведи сумата:");
- int sum = scan.nextInt();
- System.out.print("Брой монети: ");
- System.out.println(count(sum));
- }
- public static int count(int sum) {
- int coin = 0;
- int i = 0 ;
- int[] nom = {50, 20, 10, 5, 2, 1};
- while (sum > 0) {
- if (sum/nom[i] > 0){
- sum -= nom[i];
- coin++;
- }else {
- i++;
- }
- }
- return coin;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment