SHARE
TWEET

Problema dei resti

a guest Oct 23rd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top