abstract class Bench
{
abstract void bench(); public long repeat (int count)
{
long start = System.currentTimemills();
for (int i=0;i<count ;i++ )
{
bench();
}
return (System.currentTimeMills()-start);
}
class MethodBench extends Bench
{
void bench()
{
}
public void start (String[] args)
{
int count =Integer parseInt(args[0]);
long time=new Method Bench().repeat(count);
System.out.print(count + "methods in"+ time+"milliseconds");
}
}
---------- javac ----------
E:\MethodBench.java:24: ';' expected
int count =Integer parseInt(args[0]);
^
E:\MethodBench.java:25: '(' or '[' expected
long time=new Method Bench().repeat(count);
^
E:\MethodBench.java:29: '}' expected
^
3 errors输出完成 (耗时 0 秒) - 正常终止
{
abstract void bench(); public long repeat (int count)
{
long start = System.currentTimemills();
for (int i=0;i<count ;i++ )
{
bench();
}
return (System.currentTimeMills()-start);
}
class MethodBench extends Bench
{
void bench()
{
}
public void start (String[] args)
{
int count =Integer parseInt(args[0]);
long time=new Method Bench().repeat(count);
System.out.print(count + "methods in"+ time+"milliseconds");
}
}
---------- javac ----------
E:\MethodBench.java:24: ';' expected
int count =Integer parseInt(args[0]);
^
E:\MethodBench.java:25: '(' or '[' expected
long time=new Method Bench().repeat(count);
^
E:\MethodBench.java:29: '}' expected
^
3 errors输出完成 (耗时 0 秒) - 正常终止
Integer的后面少了个“.”,改成:int count =Integer.parseInt(args[0]);long time=new Method Bench().repeat(count);
Method和Bench()之间多了个空格,改成:long time=new MethodBench().repeat(count);E:\MethodBench.java:29: '}' expected
类Bench少了一个“}”,如果按照你的程序缩进,是repeat方法对应的“}”忘了敲了。
{
abstract void bench(); public long repeat (int count)
{
long start = System.currentTimemills();
for (int i=0;i<count ;i++ )
{
bench();
}
return (System.currentTimeMills()-start);
}
}
{
void bench()
{
}
public void start (String[] args)
{
int count =Integer parseInt(args[0]);
long time=new Method Bench().repeat(count);
System.out.print(count + "methods in"+ time+"milliseconds");
}
}
---------- javac ----------
E:\MethodBench.java:8: cannot find symbol
symbol : method currentTimemills()
location: class java.lang.System
long start = System.currentTimemills();
^
E:\MethodBench.java:13: cannot find symbol
symbol : method currentTimeMills()
location: class java.lang.System
return (System.currentTimeMills()-start);
^
2 errors输出完成 (耗时 0 秒) - 正常终止
{
abstract void bench(); public long repeat (int count)
{
long start = System.currentTimeMillis();
for (int i=0;i<count ;i++ )
{
bench();
}
return (System.currentTimeMillis()-start);
}
}
class MethodBench extends Bench
{
void bench()
{
}
public static void main(String[] args)
{
int count =Integer.parseInt(args[0]);
long time=new MethodBench().repeat(count);
System.out.print(count + "methods in"+ time+"milliseconds");
}
}
请楼主看准那些方法的名称
可还不对。
E:\MethodBench.java:8: cannot find symbol
symbol : method currentTimemills()
location: class java.lang.System
long start = System.currentTimemills();
^
E:\MethodBench.java:13: cannot find symbol
symbol : method currentTimeMills()
location: class java.lang.System
return (System.currentTimeMills()-start);
^
2 errors输出完成 (耗时 0 秒) - 正常终止
第8行打成了 currentTimemills
第13行 currentTimeMills
却有错误。class MethodBench extends Bench
{
void bench()
{
}
public void start (String[] args)
{
int count =Integer.parseInt(args[0]);
long time=new MethodBench().repeat(count);
System.out.print(count + "methods in"+ time+"milliseconds");
} public static void main(String args[])
{
MethodBench m=new MethodBench();
m.start();
}}---------- javac ----------
E:\MethodBench.java:34: start(java.lang.String[]) in MethodBench cannot be applied to ()
m.start();
^
1 error输出完成 (耗时 0 秒) - 正常终止
class MethodBench extends Bench
{
void bench()
{
}
public void start (String[] args)
{
int count =Integer.parseInt(args[0]);
long time=new MethodBench().repeat(count);
System.out.print(count + "methods in"+ time+"milliseconds");
} public static void main(String[] args)
{
String[] arg={"jdfk","kfdj"};
MethodBench m=new MethodBench();
m.start(arg);
}}---------- java ----------
Exception in thread "main" java.lang.NumberFormatException: For input string: "jdfk"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.parseInt(Integer.java:497)
at MethodBench.start(MethodBench.java:26)
at MethodBench.main(MethodBench.java:36)输出完成 (耗时 0 秒) - 正常终止
i不是要数字的吗?
String[]arg={"100","200"};
abstract class Bench
{
abstract void bench();
public long repeat (int count)
{
long start =System.currentTimeMillis();
for (int i=0;i<count ;i++ )
{
bench();
}
return (System.currentTimeMillis()-start);
}
}
public class MethodBench extends Bench
{
void bench(){}
public static void main (String[] args)
{
int count =Integer.parseInt(args[1]);
long time=new MethodBench().repeat(count);
System.out.print(count + "methods in"+ time+"milliseconds");
}
}
{
abstract void bench();
//private int count1=7;
public long repeat (int count)
{
//count=count1;
long start = System.currentTimeMillis();
for (int i=0;i<count ;i++ )
{
bench();
}
return (System.currentTimeMillis()-start); }
}class MethodBench extends Bench
{
void bench()
{
}
public void start (String[] args)
{
int count =Integer.parseInt(args[0]);
long time=new MethodBench().repeat(7);
System.out.print(count + " methods in "+ time+"milliseconds");
} public static void main(String[] args)
{
String[] arg={"5","90"};
MethodBench m=new MethodBench();
m.start(arg);
}}