Advertisement
Guest User

FibTesting

a guest
Oct 31st, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. public class FibTesting {
  2.  
  3.         public static void main(String[] args) {
  4.                 try{
  5.                         System.out.println(fib(30,0));
  6.                 }catch(StackOverflowError soe){
  7.                         System.out.println("Y'all overflowed.");
  8.                 }
  9.                 finally{
  10.                         System.out.println("Stack depth :"+depth);
  11.                         System.out.println("Method calls : "+calls);
  12.                 }
  13.         }
  14.         public static int depth,calls;
  15.         public static long fib(int n,int depth){
  16.                 calls++;
  17.                 if(depth > FibTesting.depth) FibTesting.depth = depth;
  18.                 if(n==1||n==2) return 1;
  19.                 return fib(n-1,depth+1)+fib(n-2,depth+1);
  20.         }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement