我正在尝试评估用户输入,但是while语句似乎在不要求输入的情况下进入了无限循环。
import javax.swing.JOptionPane;
public class StringMethodsTwo {
public static void main(String[] args)
{
String sFullName = " ";
String prompt = "Please enter your full name:";
while(sFullName.startsWith(" "));
{
sFullName = getInput(prompt);
if(sFullName.length() < 2)
{
prompt = "Please enter your full name, "<first> <middle> <last>":";
}
}
}
public static String getInput(String prompt)
{
return JOptionPane.showInputDialog(null, prompt);
}
}
你正在做循环
while(sFullName.startsWith(" ")); // while(true);
{
删除";"
去掉"while"行末尾的分号。