-
Notifications
You must be signed in to change notification settings - Fork 0
/
factorial.java
52 lines (40 loc) · 907 Bytes
/
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
47
48
49
50
51
52
// Muhammad Naveed
// Factorial
// https://www.github.com/uxlabspk/JavaCodes/
public class factorial
{
private int number;
private long factorial;
// Default constructor.
public factorial()
{
number = 0;
factorial = 1;
}
// Setter method.
public void setNumber(int number)
{
this.number = number;
}
// getter method.
public int getNumber()
{
return number;
}
// factorial finder method
public void findFactorial()
{
for (int i = number; i > 0; i--)
{
factorial *= i;
}
System.out.println("The factorial of " + getNumber() + " is " + factorial);
}
// main method
public static void main(String[] args)
{
var factorial = new factorial();
factorial.setNumber(10);
factorial.findFactorial();
}
}