There is a lot to read but it should be fairly simple. JAVA lab please computer
ID: 3828687 • Letter: T
Question
There is a lot to read but it should be fairly simple. JAVA lab please computer Lab: Calculating very Lar This assignment will focus on the m e Factorials write a Java program that the of linear linked i exact value of that integ factorial user for an integer, and are to large (up to producing n!. The size returns the ess to say, factorials containing e of quite resentation our methodology will hundreds and thousand of limitations of integers and longs in the inherent our programming languages The Storage of n! Factorials will be stored in linear linked lists in which node two 999. The first field, info will hold an containing a value from 0 through linked second field, next, holds a reference to the next node in the linear list. To be certain that the nature of this conceptualized, depicted below are the is correctly representations of and 15 628, 800 10! 628 800 I 15 1, 307, 674, 368, 000 000 l mx 368 307 I 674 Note that by storing only three digits p the placement of commasin the to the next. accomplished as just another action in stepping from one node Multiplication s The value of 15 stored Suppose that the value of 15 to be multiplied by 6 stored as ordinary s is the an in a linked list, is the multiplicand. The 6, multiplier. The multiplicand always held in a linked always a numeral between sequence o 0 and g. The action consists of a individual multiplications where the number from a are the fixed multiplier. multiplications as there nodes in the There are as many individual list holding the multiplicand Focus on Data StructuresExplanation / Answer
CODE:
package temp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Big {
static List<Integer> res = new ArrayList<>();
static int size=1;
public static void main(String[] args) {
res.add(0, 1);
// Factorial to be computed for 100.
factorial(100);
Collections.reverse(res);
System.out.println(res);
}
private static void factorial(int num) {
for(int i=2;i<=num;i++){
res = multiply(i);
}
}
private static List<Integer> multiply(int num) {
int carry = 0;
int temp=0;
for(int i=0;i<size;i++){
temp =((int)res.get(i)*num+carry);
res.set(i,temp%10);
carry=temp/10;
}
while(carry>0){
res.add(size++, carry%10);
carry=carry/10;
}
return res;
}
}
OUTPUT:
[9, 3, 3, 2, 6, 2, 1, 5, 4, 4, 3, 9, 4, 4, 1, 5, 2, 6, 8, 1, 6, 9, 9, 2, 3, 8, 8, 5, 6, 2, 6, 6, 7, 0, 0, 4, 9, 0, 7, 1, 5, 9, 6, 8, 2, 6, 4, 3, 8, 1, 6, 2, 1, 4, 6, 8, 5, 9, 2, 9, 6, 3, 8, 9, 5, 2, 1, 7, 5, 9, 9, 9, 9, 3, 2, 2, 9, 9, 1, 5, 6, 0, 8, 9, 4, 1, 4, 6, 3, 9, 7, 6, 1, 5, 6, 5, 1, 8, 2, 8, 6, 2, 5, 3, 6, 9, 7, 9, 2, 0, 8, 2, 7, 2, 2, 3, 7, 5, 8, 2, 5, 1, 1, 8, 5, 2, 1, 0, 9, 1, 6, 8, 6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.