I tried to observe the time taken by different inputs in the calculation of the nth Fibonacci number, but the output is <50ms for the first input and 0 ms for the rest Why so?
import java.io.*;
import java.util.*;
class fib{
long fibo(int s){
if(s==1 ||s==2)
return 1;
else return fibo(s-1)+(s-2);
}
}
class fibrec{
public static void main(String args[]) throws java.io.IOException{
BufferedWriter wr=new BufferedWriter(new FileWriter("C:/Users/91887/desktop/books/java/foo3.txt"));
fib f=new fib();
Random rand=new Random();
int input[]=new int[10];
for(int p=0;p<10;p++){
long st=System.currentTimeMillis();
int i=rand.nextInt(12000);
wr.write("Input : "+i+"\nOutput : "+f.fibo(i)+"\n");
long et=System.currentTimeMillis();
wr.write("Time taken = "+(et-st)+"ms\n\n");
System.out.println(st+"\t"+et+"\t"+(et-st));
}
wr.close();
}
}