-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactorial.java
More file actions
37 lines (27 loc) · 815 Bytes
/
Factorial.java
File metadata and controls
37 lines (27 loc) · 815 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
import java.util.Scanner;
// DONE 5 & 6
public class Factorial
{
public static void main(String [] args)
{
Scanner obj = new Scanner(System.in); // it has all the functions
// PROMPT
System.out.print(" Enter a number : ");
int n = obj.nextInt(); // this is assignment operator =
int factorial = 1; // default value given to remove garbage value
/*
for (int i = 1; i <= n; i++) // as per condition
{
factorial = factorial * i;
} */
int i = 1;
while(i <= n)
{
factorial = factorial * i;
i++; // manual gear
}
// OUTPUT
System.out.println(" Factorial : " + factorial);
obj.close(); // closing scanner object as this is end now
}
}