輸出內容覆蓋原有的內容
\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));
}
}
}