18.4 Reimplementing Class FactorialCalculator Using Class BigInteger

Figure 18.4 reimplements class FactorialCalculator using BigInteger variables. To demonstrate larger values than what long variables can store, we calculate the factorials of the numbers 0–50. Line 3 imports class BigInteger from package java.math. The new factorial method (lines 8–15) receives a BigInteger as an argument and returns a BigInteger

 1   // Fig. 18.4: FactorialCalculator.java 2   // Recursive factorial method. 3   import java.math.BigInteger; 4  5   public class FactorialCalculator 6   { 7      // recursive method factorial (assumes its parameter is >= 0)   8      public static BigInteger factorial(BigInteger number)          

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.