我试图显示一个字符串,然后在一段时间后将其清除。以下代码正在工作。
String hello = "Hello";
System.out.print(hello);
int length = hello.length();
for (int i = 0; i < length; i++)
System.out.print("\b");
但是当我想显示它几秒钟(使用
Thread.sleep(time)
)时,它不起作用(下面的代码)。当我调试它时,我注意到在第一次执行循环之后,光标开始指向下一行。
因此,有什么办法可以显示几秒钟然后清除它。
String hello = "Hello";
System.out.print(hello);
int length = hello.length();
Thread.sleep(10);
for (int i = 0; i < length; i++)
System.out.print("\b");
Console: support ASCII backspace symbol in console view