How to get rid of Integer.parseInt in the line:

 BigInteger i = BigInteger.valueOf(Integer.parseInt(factorial(n - 1)) * n); 

The method has the form String factorial(int n) .

  • one
    Generally speaking, calculating factorial is recursive, although it is customary for many, but incorrectly - because it is the most obvious example of recursion, it is often given in different textbooks (but only as an example!). So if you are doing non-task-to-recursion, use a normal loop. - AseN
  • 2
    @ 0xFFh considering that the author’s factorial method returns a String , then, apparently, it’s all clear what’s going on in this method, which is absolutely not connected with the optimal way of finding the factorial of a number. - Regent

2 answers 2

like this

 BigInteger i = new BigInteger(factorial(n)); 

    to fix String factorial(int n) on BigInteger factorial(int n)

    • so not interesting - OldHuman
    • one
      about the interests of the question does not say - JVic