【编程小技巧】
输出内容覆盖原有的内容
\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));
}
}
}

本文来自博客园,作者:chendsome,转载请注明原文链接:https://www.cnblogs.com/chendsome/p/18573325

浙公网安备 33010602011771号