System.out.print("\b") 会在控制台下往回删掉一个字符,如果你想回删多个字符就打印多个 "\b"
这个代码也可以参考一下:
public static void main(String[] args) throws Exception {
System.out.print("Progress:");
for (int i = 1; i <= 100; i++) {
System.out.print(i + "%");
Thread.sleep(100);
for (int j = 0; j <= String.valueOf(i).length(); j++) {
System.out.print("\b");
}
}
System.out.println();
}
A5创业网 版权所有