-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactorsAndFactorial.java
More file actions
34 lines (30 loc) · 994 Bytes
/
FactorsAndFactorial.java
File metadata and controls
34 lines (30 loc) · 994 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
import java.io.*;
public class FactorsAndFactorial {
public static void main() throws IOException {
FactorsAndFactorial obj = new FactorsAndFactorial();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("ENTER A NUMBER: ");
int num = Integer.parseInt(br.readLine());
System.out.println("FACTORS: ");
obj.displayFactors(num);
System.out.println("FACTORIAL: " + obj.calculateFactorial(num));
}
public void displayFactors(int num) {
for (int i = 1; i <= num; i++) {
if (num % i == 0) {
System.out.print(i);
if (i != num) {
System.out.print(", ");
}
}
}
System.out.println();
}
public int calculateFactorial(int num) {
int factorial = 1;
for (int i = 1; i <= num; i++) {
factorial *= i;
}
return factorial;
}
}