Skip to content

Instantly share code, notes, and snippets.

@jbandi
Created March 21, 2014 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbandi/499d182ee35317dc2111 to your computer and use it in GitHub Desktop.
Save jbandi/499d182ee35317dc2111 to your computer and use it in GitHub Desktop.
import java.time.Duration;
import java.time.Instant;
public class FibDemo {
public static void main(String[] args){
for (int i = 30; i < 50; i++) {
Instant start = Instant.now();
long res = fibonacci(i);
Instant end = Instant.now();
System.out.println("Input: " + i + " Result: " + res + ", Time: " + Duration.between(start, end).toMillis());
}
}
private static long fibonacci(int n) {
if(n == 0)
return 0;
else if(n == 1)
return 1;
else
return fibonacci(n - 1) + fibonacci(n - 2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment