import java.util.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) {
Scanner data = new Scanner(System.in);
System.out.println("Recursive Fibonacci");
System.out.println(recursiveFibonacci(4));
System.out.println(recursiveFibonacci(5));
System.out.println(recursiveFibonacci(6));
System.out.println("Fibonacci With Reduce");
System.out.println(fibonacciWithReduce(4));
System.out.println(fibonacciWithReduce(5));
System.out.println(fibonacciWithReduce(6));
}
public static int recursiveFibonacci(int number) {
if (number == 1) return 1;
return number * recursiveFibonacci(number-1);
}
public static int fibonacciWithReduce(int number) {
return Arrays
.stream(IntStream.rangeClosed(1,number).toArray())
.reduce(1, (accumulator, product) -> accumulator*product);
}
}
-
Notifications
You must be signed in to change notification settings - Fork 0
LazaroDamasceno/Fibonacci
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published