Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class domashno {
- public static void greedyAlg(int sum){
- //point 1 define arr with nominee and index for massive
- int[] nominee = {50,20,10,5,2,1};
- int index = 0;
- int counter = 0;
- while(sum > 0){
- if(sum / nominee[index] > 0){
- sum = sum - nominee[index];
- counter++;
- System.out.println("Sum is " + sum + "nominee -> " + nominee[index] + "counter -> " + counter );
- }else{
- index++;
- }
- }
- System.out.print(counter);
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //point 1 define user inputted money capacity
- System.out.print("Enter money nominee: ");
- int sum = scanner.nextInt();
- greedyAlg(sum);
- }
- }
Add Comment
Please, Sign In to add comment