Home java java, factorial calculation

java, factorial calculation

Author

Date

Category

Hello.
How to get a full number that goes beyond Long type, and accordingly issues an incorrect answer. Most likely there will be another number that will consist of two types of Long but only in order to expand registers. I do not understand how to do it.

Public Class CalculateFactorial {
Public Static Void Main (String [] Args) {
  Factorial Fact = New Factorial ();
  System.out.PrintLN (Fact.factoring (23));
}
Static Class Factorial {
  LONG RESULT = 1;
  Public Long Factoring (Long X) {
    For (long i = 1; i & lt; = x; i ++) {
      result * = i;
    }
    RETURN RESULT;
  }
}

}


Answer 1, Authority 100%

manually do not need to do, there is a type of BigInteger

public static biginteger factorial (BIGINTEGER N) {
  Biginteger Result = BigInteger.One;
  While (! n.equals (Biginteger.zero)) {
    result = result.multiply (N);
    n = n.Subtract (Biginteger.One);
  }
  RETURN RESULT;
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions