I'm trying to record the elapsed time for my method in milliseconds. Could someone tell me what I'm doing wrong?
public static void main(String[] args)
{
double pi = computePi(10000);
System.out.println(pi);
System.out.println(startTime - endTime);
}
long startTime = System.currentTimeMillis();
public static double computePi(int count)
{
double pi = 0;
for(int i = 0; i < count; i++)
{
pi += Math.pow(-1,i)/(2*i+1);
long endTime = System.currentTimeMillis();
}
return pi * 4;
return startTime - endTime;
}
}
The
computation
should be justbefore
andafter
the method call. It should beendTime-startTime
.