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();
}
申請創(chuàng)業(yè)報道,分享創(chuàng)業(yè)好點子。點擊此處,共同探討創(chuàng)業(yè)新機遇!