输出内容覆盖原有的内容
\r
表示回车符,会将光标移至开始位置,同时使用非换行形式的print
public class Main {
public static void main(String[] args) {
Random r = new Random();
String[] all = new String[10];
for (int i = 0; i <= 100; i++) {
try {
Thread.sleep(r.nextInt(100));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
all[0] = i + "%";
System.out.print("\r" +Arrays.toString(all));
}
}
}
标签:Random,技巧,编程,new,public,String
From: https://www.cnblogs.com/chendsome/p/18573325