Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
25
Task/Continued-fraction/Java/continued-fraction.java
Normal file
25
Task/Continued-fraction/Java/continued-fraction.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import static java.lang.Math.pow;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Test {
|
||||
static double calc(Function<Integer, Integer[]> f, int n) {
|
||||
double temp = 0;
|
||||
|
||||
for (int ni = n; ni >= 1; ni--) {
|
||||
Integer[] p = f.apply(ni);
|
||||
temp = p[1] / (double) (p[0] + temp);
|
||||
}
|
||||
return f.apply(0)[0] + temp;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Function<Integer, Integer[]>> fList = new ArrayList<>();
|
||||
fList.add(n -> new Integer[]{n > 0 ? 2 : 1, 1});
|
||||
fList.add(n -> new Integer[]{n > 0 ? n : 2, n > 1 ? (n - 1) : 1});
|
||||
fList.add(n -> new Integer[]{n > 0 ? 6 : 3, (int) pow(2 * n - 1, 2)});
|
||||
|
||||
for (Function<Integer, Integer[]> f : fList)
|
||||
System.out.println(calc(f, 200));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue