Java program find factorial value of given number

Write a java program find factorial value of given number

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package logic;
 
import java.util.Scanner;
 
public class Factorial 
{
 
	public static void main(String[] args) {
 
		int f;
		Scanner c=new Scanner(System.in);
		System.out.println("enter a number");
		f=c.nextInt();
		int x=1;
 
 
		for(int i=1;i<=f;i++)
 
		{
		x=x*i	;
 
		}
 
		System.out.println("factorial value "+x);
 
	// using while loop	
 
	/*	while(f!=0)
 
	{
 
			 x=x*f;
			 f--;
		}
		System.out.println("factoral value ="+x);
 
		*/
 
 
	}
 
}

output:

1
2
3
enter a number
5
factorial value 120

Leave a Reply

Your email address will not be published. Required fields are marked *