Questo lo calcola e dovrebbe calcolare il fattoriale di qualsiasi numero gli si dia in input... :gren:
codice:
import java.io.*;
import java.math.*;
public class Fattoriale {
public static void main(String [] args) throws Exception {
String valore;
int val;
BufferedReader br = new BufferedReader( new InputStreamReader(System.in) );
System.out.println("Introdurre il valore di cui calcolare il fattoriale: ");
valore = br.readLine();
val = Integer.parseInt(valore);
System.out.println();
System.out.println("Il fattoriale vale: " + fatt(val));
}
public static BigInteger fatt(int valore) {
BigInteger result;
if (valore == 0) {
result = new BigInteger("" + 1);
} else {
result = (new BigInteger("" + valore)).multiply(fatt(valore-1));
}
return result;
}
}
Ciao.