s l e e p ( ) sleep() sleep()方法:使当前执行的线程在指定的毫秒数内休眠(暂时停止执行)
注: s l e e p ( ) sleep() sleep()方法执行时会抛出异常 I n t e r r u p t e d E x c e p t i o n InterruptedException InterruptedException 需要使用 t r y c a t c h try\ catch try catch语句捕捉异常。
public class Test { public static void main(String[] args) { for (int i = 0; i < 60; i++) { System.out.println(i); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }