Java Program to Calculate Factorial of given Number

0 0
Read Time:18 Second
import java.util.Scanner;
public class Factorial
{
    public static void main(String[] args) {
		int number,fact=1;
        Scanner input=new Scanner(System.in);
        System.out.println("Enter a Number:");
        number=input.nextInt();
        for(int i=1;i<=number;i++)
        {
            fact=fact*i;
        }
        System.out.println("Factorial of "+number+" is "+fact);
	}
}

/*

Output:
Enter the number: 5
Factorial of 5 is 120

*/
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Comment

Verified by MonsterInsights