0

我正在尝试以毫秒为单位记录我的方法经过的时间。有人可以告诉我我做错了什么吗?

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;
}

}

4

1 回答 1

0

computation应该只是before和方法after调用。应该是endTime-startTime

public static void main(String[] args)
{
     long startTime = System.currentTimeMillis();
     double pi = computePi(10000);
     long endTime = System.currentTimeMillis();

     System.out.println(pi);

     System.out.println(endTime- startTime);
}
于 2014-11-15T04:41:49.760 回答