You are here: Home &rarr Personal &rarr The 25 Factorial in Java

The 25 Factorial in Java

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);
}
}

Tags: ,


About Chinmoy


Chinmoy Kanjilal is the admin of this blog is a programmer and a technology, Linux and web2.0 enthusiast and evangelist from India with an eye for detail. He has a fondness for intriguing software products and hardware hacks.

  • Ujjwal
    keep up the good work n join the new innovation club in collg!
blog comments powered by Disqus
Content on this Blog is Copyright © 2010 Techarraz. Some rights reserved.
Designed by Theme Junkie. Powered by WordPress.