//求某段代码的运行时间
//System.currentTimeMillis()
abstract class GetTime
{
public final void getTime(){
long start=System.currentTimeMillis();
code();
long end=System.currentTimeMillis();
System.out.println("毫秒:"+(end-start));
}
public abstract void code();
}
class Test extends GetTime
{
public void code(){
for(int i=0;i<1000;i++){
System.out.println(i);
}
}
public static void main(String[] args)
{
GetTime g=new Test();
g.getTime();
}
}
//System.currentTimeMillis()
abstract class GetTime
{
public final void getTime(){
long start=System.currentTimeMillis();
code();
long end=System.currentTimeMillis();
System.out.println("毫秒:"+(end-start));
}
public abstract void code();
}
class Test extends GetTime
{
public void code(){
for(int i=0;i<1000;i++){
System.out.println(i);
}
}
public static void main(String[] args)
{
GetTime g=new Test();
g.getTime();
}
}