字符串不等于

时间:2020-02-11 03:31:35

标签: java string

我当时正在为一个简单的猜谜游戏制作一个程序(用户想到一个数字,而计算机试图猜谜)。执行此while循环时遇到问题。即使我输入“ l”,“ h”或“ c”,while循环似乎无限地在询问“请重新输入”。

public static void play() {
    inputBounds();
    while((ub-lb) < 20 || lb<=0) {
        System.out.println("Upper bound – lower bound must be >= 20. ");
        inputBounds();
    }
    int guess = gen.nextInt((ub-lb) + 1) + lb;
    System.out.println("I guess, the answer is " + guess);
    System.out.print("Your answer is (h=higher than you thought, l=lower than you thought, c=correct):");
    String hint = input.next();
    while(!hint.equalsIgnoreCase("l") || !hint.equalsIgnoreCase("h") || !hint.equalsIgnoreCase("c")) {
        System.out.print("Please retype.");
        hint = input.next();
    }

}

0 个答案:

没有答案
相关问题