-
Notifications
You must be signed in to change notification settings - Fork 0
/
Factorial.java
46 lines (39 loc) · 1.03 KB
/
Factorial.java
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
43
44
45
46
// import java.util.Scanner;
// class Factorial1{
// public void fact(int n)
// {
// int m = n;
// int fact = 1;
// for(int i=0;i<=m;i++)
// {
// fact = fact*i;
// }
// System.out.println("Factorial of the number is : " + m);
// }
// }
// public class Factorial {
// public static void main(String[] args) {
// int number;
// Scanner num = new Scanner(System.in);
// Factorial1 fac = new Factorial1();
// System.out.println("Please enter the Factorial number : ");
// number = num.nextInt(); //3628800
// fac.fact(number);
// }
// }
import java.util.Scanner;
public class Factorial
{
public static void main(String[] args)
{
int num, i, fact=1;
Scanner s = new Scanner(System.in);
System.out.print("Enter a Number: ");
num = s.nextInt();
for(i=num; i>=1; i--)
{
fact = fact*i;
}
System.out.println("\nFactorial Result = " +fact);
}
}