高手,帮忙指出怎么改
abstract class Benchmark
{
abstract void benchmark();
public long repeat (int count)
{
long start = System.currentTimemills();
for (int i=0;i <count ;i++ )
{
benchmark();
}
return (System.currentTimeMills()-start);
}
class MethodBenchmark extends Benchmark
{
void benchmark()
{
}
public void start (String[] args)
{
int count =Integer parseInt(args[0]);
long time=new Method Benchmark().repeat(count);
System.out.print(count + "methods in "+ time+ "milliseconds ");
}
}
---------- javac ----------
E:\MethodBenchmark.java:24: '; ' expected
int count =Integer parseInt(args[0]);
^
E:\MethodBenchmark.java:25: '( ' or '[ ' expected
long time=new Method Benchmark().repeat(count);
^
E:\MethodBenchmark.java:29: '} ' expected
^
3 errors
输出完成 (耗时 0 秒) - 正常终止
------解决方案--------------------int count =Integer parseInt(args[0]);
Integer的后面少了个“.”,改成:int count =Integer.parseInt(args[0]);
long time=new Method Benchmark().repeat(count);
Method和Benchmark()之间多了个空格,改成:long time=new MethodBenchmark().repeat(count);
E:\MethodBenchmark.java:29: '} ' expected
类Benchmark少了一个“}”,如果按照你的程序缩进,是repeat方法对应的“}”忘了敲了。
------解决方案--------------------abstract class Benchmark
{
abstract void benchmark();
public long repeat (int count)
{
long start = System.currentTimemills();
for (int i=0;i <count ;i++ )
{
benchmark();
}
return (System.currentTimeMills()-start);
}
}
------解决方案--------------------应该是 System.currentTimeMillis()
第8行打成了 currentTimemills
第13行 currentTimeMills
------解决方案--------------------标准的代码请楼主看下面的:
abstract class Benchmark
{
abstract void benchmark();
public long repeat (int count)
{
long start =System.currentTimeMillis();
for (int i=0;i <count ;i++ )
{
benchmark();
}
return (System.currentTimeMillis()-start);
}
}
public class MethodBenchmark extends Benchmark
{
void benchmark(){}
public static void main (String[] args)
{
int count =Integer.parseInt(args[1]);
long time=new MethodBenchmark().repeat(count);
System.out.print(count + "methods in "+ time+ "milliseconds ");
}
}