Java每隔一段时间输出一句话

while (true) {

    Thread.sleep(1000);//等待1S
    System.out.println("----------");
}
 
要限制第几次输出结束:例如: 输出第五次结束
int a = 0;

while (a<5) {

    Thread.sleep(1000);//等待1S
a+= 1;
    System.out.println("-----");
}
原文地址:https://www.cnblogs.com/bichen-01/p/12108759.html