I m a Java newbie and I m trying to deploy a fibonacci trail through recursive function and then calculate the run time. here is the code I have managed to write:
class nanoTime{
int fib(int n){
if(n==0) return 0;
if(n==1) return 1;
return this.fib(n-1)+this.fib(n-2);
}
public static void main(String[] args){
double beginTime,endTime,runTime;
int n=10;
beginTime = System.nanoTime();
n = this.fib(n);
endTime = System.nanoTime();
runTime = endTime-beginTime;
System.out.println("Run Time:" + runTime);
}
}
问题在于,我试图将其变为Byte-code I时有以下错误:
nanoTime.java:11: non-static variable this cannot be referenced from a static context
我想知道问题是什么?