Java output word from time to time

while (true) {

     Thread.sleep( 1000 ); //等待1S
     System.out.println( "----------" );
}
 
To limit the output end of the times: for example: the output end of the fifth
int a = 0;

while (a<5) {

     Thread.sleep( 1000 ); //等待1S
a+= 1;
     System.out.println( "-----" );
}

Guess you like

Origin www.cnblogs.com/bichen-01/p/12108759.html