In Java, the factorial of large numbers can be easily implemented in SE6 using the bigInteger class. The logic is the same as for finding factorials. The code goes as follows:
import java.math.BigInteger;
import java.lang.*;
import java.util.Scanner;
class largenumber
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a number for factorial");
int num=in.nextInt();
BigInteger fact=BigInteger.valueOf(1);
for(int i=2;i<=num;i++)
{
fact=fact.multiply(BigInteger.valueOf(i));
}
System.out.println("Factorial "+num+" is ::nt"+fact);
}
}
Compared to the C code for factorial of large numbers, this is fairly simple and easy to implement.
Chinmoy Kanjilal is the geek behind Techarraz. This is where he rants about his adventures with technology. Get to know him better, and connect with him on social networks.
keep up the good work n join the new innovation club in collg!