我正在尝试评估用户输入,但是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);
}
}
答案 0 :(得分:1)
你正在做循环
while(sFullName.startsWith(" ")); // while(true);
{
删除“;”
答案 1 :(得分:0)
在“while”行的末尾丢失分号。