Factorial.java 651B

1234567891011121314151617181920212223242526
  1. import java.math.BigInteger;
  2. public class Factorial {
  3. public BigInteger factorialOf(Integer value){
  4. BigInteger factorialValue = BigInteger.valueOf(1);
  5. for (int i=1;i<=value;i++) {
  6. factorialValue = factorialValue.multiply(BigInteger.valueOf(i));
  7. }
  8. return factorialValue;
  9. }
  10. /* Overflow
  11. public String factorialOf1000(){
  12. int value = 1000;
  13. BigInteger factorialValue = new BigInteger("1");
  14. for (int i=1;i<=value;i++) {
  15. factorialValue = factorialValue.multiply(new BigInteger(i + ""));
  16. }
  17. return factorialValue.toString();
  18. }
  19. */
  20. }