Advertisement
Guest User

Problema dei resti

a guest
Oct 23rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. package test.resti;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5.  
  6. public class AppResti {
  7.  
  8.     private static final List<Integer> TAGLI = Arrays.asList(200, 100, 50, 20, 10, 5, 2, 1);
  9.  
  10.     public static void main(String[] args) {
  11.         Integer importo = getImporto(args);
  12.         for (int taglioCorrente : TAGLI) {
  13.             int quantitaTaglioCorrente = importo / taglioCorrente;
  14.             importo = importo % taglioCorrente;
  15.             System.out.println(quantitaTaglioCorrente + " da " + taglioCorrente);
  16.         }
  17.     }
  18.  
  19.     private static Integer getImporto(String[] args) {
  20.         if (args.length < 1) {
  21.             throw new IllegalArgumentException("Parametro importo non passato");
  22.         }
  23.         return Integer.parseInt(args[0]);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement