Advertisement
Dimitar182

Untitled

Dec 16th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class homework {
  3.  
  4. public static void main(String[] args) {
  5.  
  6. Scanner scan = new Scanner(System.in);
  7. System.out.println("INPUT SUM : ");
  8. int Sum = scan.nextInt();
  9. CountNominees(Sum);
  10.  
  11.  
  12.  
  13. }//end of main
  14.  
  15. public static void CountNominees(int Sum) {
  16. int counter = 0;
  17. int index = 0;
  18. int [] nominees = {50,20,10,5,2};
  19.  
  20. while (Sum > 0) {
  21.  
  22. if(Sum/nominees[index] > 0) {
  23.  
  24.  
  25. Sum = Sum - nominees[index];
  26. counter++;
  27. System.out.println(Sum + nominees[index] + "(-" + nominees[index] + ")" + "COUNTER : " + counter);
  28. }
  29. else
  30. if (index+1 < nominees.length)
  31. index++;
  32. else{
  33. System.out.println("NO MORE NOMINALS FOR THIS SUM : " + Sum );
  34. break;
  35. }
  36. }
  37.  
  38. System.out.println();
  39. System.out.println("COUNTER IS : " + counter);
  40.  
  41.  
  42.  
  43.  
  44. }//end of method CountNominees
  45.  
  46. }//end of class
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement