forked from ghostmkg/programming-language
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactorial.java
More file actions
Latest commit
17 lines (14 loc) · 518 Bytes
/
Copy pathfactorial.java
File metadata and controls
17 lines (14 loc) · 518 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
importjava.util.Scanner;
publicclassFactorialIterative {
publicstaticvoidmain(String[] args) {
Scannerscanner = newScanner(System.in);
System.out.print("Enter a number: ");
intnumber = scanner.nextInt();
longfactorial = 1;
for (inti = 1; i <= number; i++) {
factorial *= i; // multiply current number with the accumulated result
}
System.out.println("Factorial of " + number + " is: " + factorial);
scanner.close();
}
}