例如,不要打印
在新的一行上,让它保持在一行上并成为一个旋转器动画?
/
-
\
/
在新的一行上,让它保持在一行上并成为一个旋转器动画?
是的,打印一个 \b
(退格)来删除最后一个字符。简而言之:
System.out.print('/');
System.out.print('\b');
System.out.print('-');
System.out.print('\b');
System.out.print('\\');
System.out.print('\b');
import java.io.*;
class Load_Animate
{
static byte anime;
static void animate(int i)
{
try
{
for(int j = 0 ; j<=100 ; j++)
{
switch(anime)
{
case 1:
System.out.print("\r[ \\ ] :" + j + "%");
break;
case 2:
System.out.print("\r[ | ] :" + j + "%");
break;
case 3:
System.out.print("\r[ / ] :" + j + "%");
break;
default:
anime = 0;
System.out.print("\r[ - ] :" + j + "%");
}
anime++;
Thread.sleep(i);
}
}
catch(InterruptedException e)
{
System.out.println(e);
}
}
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int i = Integer.parseInt(br.readLine());
animate(i);
}
}
这是我所做的: 我使用了"\r",这是一个回车符,基本上将光标指向行的第一位置。
如果您需要文本光标定位,解决方案将需要通过JNI。您需要一些C光标定位软件,这将是不可移植的。Curses是15-20年前流行的应用程序。
问题是,您真的需要回到过去吗?