-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactorialLong.java
61 lines (44 loc) · 1.38 KB
/
FactorialLong.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
53
54
55
56
57
58
59
60
61
package org.main;
import java.math.BigInteger;
import java.util.Scanner;
public class FactorialLong {
public static void main(String[] args) {
Scanner sin = new Scanner(System.in);
int n = sin.nextInt();
String fact = factorial(n);
System.out.println("Factorial is " + fact);
}
public static String factorial(int n) {
BigInteger fact = new BigInteger("1");
for (int i = 1; i <= n; i++) {
fact = fact.multiply(new BigInteger(i + ""));
System.out.println("i is:"+i);
}
return fact.toString();
}
//BigInteger f = BigInteger.ONE;
/*public static void main(String[] args) {
Scanner sin = new Scanner(System.in);
BigInteger n = sin.nextBigInteger();
FactorialLong fl = new FactorialLong();
System.out.println(fl.findFact(n));
}
public BigInteger findFact(BigInteger n){
if(n < 2){
return f;
}
else{
f= findFact(n-1)*n;
}
int counter ;
BigInteger increment = new BigInteger("1");
BigInteger f = new BigInteger("1");
for (counter = 1; counter <= n.longValueExact(); counter++) {
System.out.println("counter:"+counter);
f = f.multiply(increment);
increment = increment.add(BigInteger.ONE);
}
System.out.println(String.valueOf(f));
return f;
}*/
}