HomeWork1:统计程序的运行时间
public static void main(String[] args) throws InterruptedException {
//1.获取运行前的时间
long startTime = System.currentTimeMillis();
//2.需要计算运行时间的程序
Thread.sleep(3000);//让程序睡三秒
//3.获取运行后的时间
long endTime = System.currentTimeMillis();
//4.打印程序的运行时间
System.out.println("程序运行了:" + (endTime - startTime) + "毫秒");
}

浙公网安备 33010602011771号