📄 stopwatch1.java
字号:
// (c) Copyright 1997-2001 Recursion Software Inc.
package examples.timer;
import com.recursionsw.lib.timer.*;
public class Stopwatch1
{
public static void main( String args[] )
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.setRecordLapTimes( true ); // record individual lap times
System.out.println( "start the stopwatch and then sleep for 2 seconds" );
stopwatch.start();
try{ Thread.sleep( 2000 ); } catch( InterruptedException exception ) {}
System.out.println( "stop the stopwatch" );
stopwatch.stop();
System.out.println( "lap count = " + stopwatch.getLapCount() );
System.out.println( "lap time = " + stopwatch.getLapTime() );
System.out.println( "total time = " + stopwatch.getTotalTime() );
System.out.println( "pause for 4 seconds" );
try{ Thread.sleep( 4000 ); } catch( InterruptedException exception ) {}
System.out.println( "start the stopwatch and then sleep for 3 seconds" );
stopwatch.start();
try{ Thread.sleep( 3000 ); } catch( InterruptedException exception ) {}
System.out.println( "stop the stopwatch" );
stopwatch.stop();
System.out.println( "lap count = " + stopwatch.getLapCount() );
System.out.println( "lap time = " + stopwatch.getLapTime() );
System.out.println( "total time = " + stopwatch.getTotalTime() );
System.out.println( "average lap time = " + stopwatch.getAverageLapTime() );
long[] times = stopwatch.getLapTimes();
System.out.print( "lap times = [ " );
for( int i = 0; i < times.length; i++ )
System.out.print( times[ i ] + " " );
System.out.println( "]" );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -