Table of Contents

*Java program for factorial number*. Here I have tried to introduce you a simple factorial program. This is an automated factorial java program going to design. To find factorial of a number I have divided this factorial java program into tree basic part to make you easily understand. Must check Armstrong number program in Java and Palindrome number in java.

## Factorial program part

Division of java program to find factorial of a number. Such as:-

*Java program for**factorial*smaller number less than 50. Download- Factorial of large numbers in java using BitInteger. Download
- Design a single factorial java program to get
**factorial**of any number. Download

Above I have described the brief of this article that how? this is going to go **write a program to find factorial of a number**. To make easy to understand I have decided this algorithm to find factorial of a number into three basic part.

So let’s see what is the first factorial program. Visit on How to reverse a number in java.

**Java program for factorial **smaller number less than 50

This first program is simpler for loop programs in java with output. Using this **java program** users can get factorial number between the greater than 1 and less than 50. Here this “java program for factorial” users can modify the grater boundary number Which I have fixed 50. This boundary number users can set till the 64 bit only.

This ‘factorial java program; boundary number users can set till 64 bit only because I have used here data types **long**, Which has the limitation of 64 bit. So now let’s see the **algorithm to find factorial of a number**. Count repeated character in a string.

1| |
import java.util.*; | |||||||||||

2| |
import java.math.*; | |||||||||||

3| |
public class factorial | |||||||||||

4| |
{ | |||||||||||

5| |
static void fact(long x) | |||||||||||

6| |
{ | |||||||||||

7| |
long num=x; | |||||||||||

8| |
long factrial_each_num_multiplication=1; | |||||||||||

9| |
if (x>0) | |||||||||||

10| |
{ | |||||||||||

11| |
for (int i=0; i<num; i++) | |||||||||||

12| |
{ | |||||||||||

13| |
factrial_each_num_multiplication=factrial_each_num_multiplication*x; | |||||||||||

14| |
x–; | |||||||||||

15| |
} | |||||||||||

16| |
System.out.print(“This is sum of factorial number ::”+factrial_each_num_multiplication); | |||||||||||

17| |
} | |||||||||||

18| |
} | |||||||||||

19| |
public static void main(String[] args) | |||||||||||

20| |
{ | |||||||||||

21| |
Scanner input=new Scanner(System.in); | |||||||||||

22| |
System.out.print(“Enter number here :: “); | |||||||||||

23| |
long sum_of_acetoria_number=input.nextInt(); | |||||||||||

24| |
fact(sum_of_acetoria_number); | |||||||||||

25| |
System.out.println(); | |||||||||||

26| |
} | |||||||||||

27| |
} |

**Java program for factorial **smaller number less than 50: Output

**Factorial of large numbers in java** using BitInteger

* Factorial program in java using scanner *class and biginteger range

**.**To use BigInteger range here I have imported a package, Which we call by import java.util.BigInteger; This helps to design

**algorithm to find factorial of any number**. This BigInterger data type is a string.

Also, you can use java factorial recursive method and many more asked me to make **factorial program in java without using a loop **which is not good practice. Suggested program Find the minimum and maximum sum.

So let’s see “java program for factorial number”.

3| |
import java.util.*; | |||||||

4| |
import java.math.BigInteger; | |||||||

5| |
public class bigint | |||||||

6| |
{ | |||||||

7| |
public static void main(String[] args) | |||||||

8| |
{ | |||||||

9| |
Scanner input=new Scanner(System.in); | |||||||

10| |
int i=input.nextInt(); | |||||||

11| |
System.out.println(fact(i)); | |||||||

12| |
} | |||||||

13| |
static BigInteger fact(int n) | |||||||

14| |
{ | |||||||

15| |
BigInteger ans=new BigInteger(“1”); | |||||||

16| |
for (int i=2; i<=n; i++) | |||||||

17| |
{ | |||||||

18| |
ans=ans.multiply(BigInteger.valueOf(i)); | |||||||

19| |
} | |||||||

20| |
return (ans); | |||||||

21| |
} | |||||||

22| |
} |

**Factorial of large numbers in java** using BitInteger: Output

##### Design a single **factorial java program** to get **factorial **of any number

Mostly have asked that *how to write a program in java* for factorial any number. To get this first you are strongly required to understand first both method because of this last method nothing but only I have merged first and the second method to find factorial of a number.

So let’s see this how to write a program in java for an amazing algorithm to find factorial of a number.

1| |
import java.util.*; | |||||||||||

2| |
import java.math.BigInteger; | |||||||||||

3| |
||||||||||||

4| |
public class factto | |||||||||||

5| |
{ | |||||||||||

6| |
public static void main(String[] args) | |||||||||||

7| |
{ | |||||||||||

8| |
System.out.print(“Enter number here :: “); | |||||||||||

9| |
Scanner input=new Scanner(System.in); | |||||||||||

10| |
int i=input.nextInt(); | |||||||||||

11| |
System.out.println(); | |||||||||||

12| |
if (i<=50) | |||||||||||

13| |
{ | |||||||||||

14| |
fact(i); | |||||||||||

15| |
}else | |||||||||||

16| |
{ | |||||||||||

17| |
fact(i); | |||||||||||

18| |
} | |||||||||||

19| |
System.out.println(fact(i)); | |||||||||||

20| |
System.out.println(); | |||||||||||

21| |
} | |||||||||||

22| |
static BigInteger fact(int n) | |||||||||||

23| |
{ | |||||||||||

24| |
BigInteger ans=new BigInteger(“1”); | |||||||||||

25| |
for (int i=2; i<=n; i++) | |||||||||||

26| |
{ | |||||||||||

27| |
ans=ans.multiply(BigInteger.valueOf(i)); | |||||||||||

28| |
} | |||||||||||

29| |
return (ans); | |||||||||||

30| |
} | |||||||||||

31| |
static void fact(long x) | |||||||||||

32| |
{ | |||||||||||

33| |
long num=x; | |||||||||||

34| |
long factrial_each_num_multiplication=1; | |||||||||||

35| |
if (x>0) | |||||||||||

36| |
{ | |||||||||||

37| |
for (int i=0; i<num; i++) | |||||||||||

38| |
{ | |||||||||||

39| |
factrial_each_num_multiplication=factrial_each_num_multiplication*x; | |||||||||||

40| |
x–; | |||||||||||

41| |
} | |||||||||||

42| |
System.out.print(“This is sum of factorial number ::”+factrial_each_num_multiplication); | |||||||||||

43| |
} | |||||||||||

44| |
} | |||||||||||

45| |
} |

##### Design a single **factorial java program** to get **factorial **of any number: Output

**Java program for factorial comment**

In this all three **factorial java program **you will that I have used a common **for loop programs in java with output **because using this for loop it makes an easier program for both such as in understanding and to deliver output faster**.**

In all, I have not used high funda to make typical. Above following or understanding **factorial program **if you face any difficulty so let me know by the below-commenting box.

Keep connected with Https://infosorce.com to get more useful **java program**.

## Speak Your Mind