forked from deepanshdubey/JavaAssignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactorial.java
More file actions
27 lines (26 loc) · 695 Bytes
/
Factorial.java
File metadata and controls
27 lines (26 loc) · 695 Bytes
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
//Author : Deepansh Dubey.
//Date : 2/09/2021.
//Purpose : To find the factorial of a given number.
import java.io.*;
class Factorial
{
public void factorial(int a)
{
int i=a; long fact = 1;
while(i!=1)
{
fact = fact*i;
i--;
}
System.out.println("The factorial of " + a + " is " + fact);
}
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n;
System.out.println("Enter a number.");
n=Integer.parseInt(br.readLine());
Factorial ob=new Factorial();
ob.factorial(n);
}
}