Advertisement
piffy

Fattoriale

Jul 17th, 2021
2,429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.68 KB | None | 0 0
  1. import java.util.concurrent.Callable;
  2. import java.util.concurrent.TimeUnit;
  3.  
  4. class Fattoriale implements Callable<Integer>
  5. {
  6.     private final Integer numero;
  7.     public Fattoriale(Integer numero) {
  8.         this.numero = numero;
  9.     }
  10.     @Override
  11.     public Integer call() throws Exception {
  12.  
  13.         int risultato = 1;
  14.         if ((numero == 0) || (numero == 1)) {
  15.             risultato = 1;
  16.         } else {
  17.             for (int i = 2; i <= numero; i++) {
  18.                 risultato *= i;
  19.                 TimeUnit.MILLISECONDS.sleep(20);
  20.             }
  21.         }
  22.  
  23.         System.out.printf("Il fattoriale di %d รจ %d\n", numero, risultato);
  24.         return risultato;  }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement