Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class GreedyAlgorithm {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int sum = Integer.parseInt(scan.nextLine());
- CountNominees(sum);
- }
- private static void CountNominees(int sum) {
- int counter = 0;
- int index = 0;
- int[] nominees = {50, 20, 10,};
- while (sum > 0) {
- if (nominees[index] <= sum){
- sum = sum - nominees[index];
- counter++;
- System.out.println(sum + nominees[index] + (" - " + nominees[index] + ";") + " COUNTER IS:" + counter);
- } else if (index + 1 < nominees.length) {
- index++;
- } else {
- System.out.println("NO MORE NOMINEES FOR THIS SUM :" + sum);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement