Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FibTesting {
- public static void main(String[] args) {
- try{
- System.out.println(fib(30,0));
- }catch(StackOverflowError soe){
- System.out.println("Y'all overflowed.");
- }
- finally{
- System.out.println("Stack depth :"+depth);
- System.out.println("Method calls : "+calls);
- }
- }
- public static int depth,calls;
- public static long fib(int n,int depth){
- calls++;
- if(depth > FibTesting.depth) FibTesting.depth = depth;
- if(n==1||n==2) return 1;
- return fib(n-1,depth+1)+fib(n-2,depth+1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement