do-while循环不能正常工作

Dra*_*olf 2 java do-while

好吧基本上我很难找到为什么这不起作用,因为我认为它应该,并需要帮助获得正确的输出.我试过用这种格式搞砸几种方法,但没有任何作用,我真的不明白为什么.以下是说明,其后是我的来源:

说明

编写一个循环,从标准输入读取字符串,其中字符串是"land","air"或"water".当读入"xx​​xxx"(五个x字符)时,循环终止.忽略其他字符串.在循环之后,你的代码应打印出3行:第一行包含字符串"land:",后跟读入的"land"字符串的数量,第二行包含字符串"air:",后跟数字" air"字符串读入,第三个字符串由"water:"组成,后跟读入的"water"字符串数.每个字符串应打印在单独的行中.

ASSUME变量stdin的可用性,该变量引用与标准输入关联的Scanner对象.

资源:

int land = 0;
int air = 0;
int water = 0;

do
{
     String stdInput = stdin.next();
        if (stdInput.equalsIgnoreCase("land"))
        {
            land++;
        }else if (stdInput.equalsIgnoreCase("air"))
        {
            air++;
        }else if (stdInput.equalsIgnoreCase("water"))
        {
            water++;
        }
}while (stdin.equalsIgnoreCase("xxxxx") == false); // I think the issue is here, I just dont't know why it doesn't work this way
System.out.println("land: " + land);
System.out.println("air: " + air);
System.out.println("water: " + water);
Run Code Online (Sandbox Code Playgroud)

Psh*_*emo 5

您正在存储用户信息,stdInput但需要检查stdin.试试这种方式

String stdInput = null;

do {
    stdInput = stdin.next();

    //your ifs....

} while (!stdInput.equalsIgnoreCase("xxxxx"));
Run Code Online (Sandbox Code Playgroud)