with语句来比较字符串

时间:2015-01-28 21:20:35

标签: string loops while-loop compare infinite

我正在尝试评估用户输入,但是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);
    }
}

2 个答案:

答案 0 :(得分:1)

你正在做循环

while(sFullName.startsWith(" ")); // while(true);
{

删除“;”

答案 1 :(得分:0)

在“while”行的末尾丢失分号。