-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfac.java
More file actions
43 lines (41 loc) · 738 Bytes
/
Copy pathfac.java
File metadata and controls
43 lines (41 loc) · 738 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.Scanner;
class Factorial1
{
int fact,n;
void setvalue(int a)
{
fact=1;
n=a;
}
}
class Factorial2 extends Factorial1
{
void calculate()
{
for (int i=1;i<=n;i++)
{
fact =fact*i;
}
}
}
class Factorial3 extends Factorial2
{
void display()
{
System.out.println("factorial of"+n+"is:"+fact);
}
}
public class fac
{
public static void main(String args[])
{
int num;
Scanner sc=new Scanner(System.in);
System.out.println("enter a value:");
num =sc.nextInt();
Factorial3 f=new Factorial3();
f.setvalue(num);
f.calculate();
f.display();
}
}