piffy icon

Fattoriale

piffy | PRO | 07/17/21 01:36:52 PM UTC | 0 ⭐ | 12327 👁️ | Never ⏰ | []
Java 5 |

0 B

|

None

|

0 👍

/

0 👎

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
 
class Fattoriale implements Callable<Integer>
{
    private final Integer numero;
    public Fattoriale(Integer numero) {
        this.numero = numero;
    }
    @Override
    public Integer call() throws Exception {
 
        int risultato = 1;
        if ((numero == 0) || (numero == 1)) {
            risultato = 1;
        } else {
            for (int i = 2; i <= numero; i++) {
                risultato *= i;
                TimeUnit.MILLISECONDS.sleep(20);
            }
        }
 
        System.out.printf("Il fattoriale di %d è %d\n", numero, risultato);
        return risultato;  }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎