Question: 1. To go beyond the primitive types, we need to use a new class. Fortunately, the BigInteger class is one of the standard Java classes,


1. To go beyond the primitive types, we need to use a new class. Fortunately, the BigInteger class is one of the standard Java classes, so to get extremely large integers, we can use this class. Copy the program factorial.java to bifactorial.java using the cp command. Now, go in and change the class name to bifactorial. Think about and modify all of the places where you will need to change int to BigInteger (result variable declaration at the end of main, method return type, method local variable). 2. Changing to a non-primitive value takes a bit of doing. First of all, you need to include the library at the top of the program with import java.math. BigInteger; 3. Second, in the fact class method, there is no direct conversion between integers and BigIntegers, so you'll need to replace product = 1; with BigInteger product BigInteger.ONE; BigInteger.ONE is a public class variable in the BigInteger class. Your parameter will still be a regular, simple int and your for loop index will be an int too. If you are using an integer value other than 0 or 1, you can create a new BigInteger with its value using BigInteger.valueof (the integer). So, you could have initialized the product using product BigInteger.valueOf (1); 4. Finally, you can not use the standard mathematical symbols +, -, *, etc on new types. (Some programming languages do allow you to redefine these, but Java is not one of those languages.) So, it should look like this: private static BigInteger fact (int n) { BigInteger product BigInteger.ONE; for (int i = 2; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
