我想制作一个命令行程序,只用于运行基本命令。到目前为止,我已经让人们告诉程序他们的名字。然而,如果我没有输入名字,它会将其视为我已经输入了。这是我的类:
public static void main(String args[])
throws IOException
{
int a = 1;
do
{
System.out.print("$$: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String wtt = null; // wtt = what they typed!
wtt = br.readLine();
if(wtt == null)
{
System.out.println("Why wont you tell me your name!");
}
else
{
System.out.println("Thanks for the name, " + wtt);
}
}
while(a == 1);
}
这是输出结果:
为什么它不起作用?$$:好的
谢谢你的名字,好的
$$:洞
谢谢你的名字,洞
$$:
谢谢你的名字,