String with语句来比较字符串

String with语句来比较字符串,string,loops,while-loop,compare,infinite,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:"; w

我试图评估用户输入,但是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);
    }
}
import javax.swing.JOptionPane;
公共类StringMethodsTwo{
公共静态void main(字符串[]args)
{
字符串sFullName=“”;
String prompt=“请输入您的全名:”;
while(sFullName.startsWith(“”);
{
sFullName=getInput(提示);
if(sFullName.length()<2)
{
prompt=“请输入您的全名,\”\:”;
}
}
}
公共静态字符串getInput(字符串提示)
{
return JOptionPane.showInputDialog(null,提示符);
}
}

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

您正在执行循环

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

删除“;”

你的问题是什么?你有什么问题?我如何避免无限循环。程序从不要求输入。