您如何忽略大小写。我做了一个显示菜单,当我输入小写字母时,会发生正确的输出,但是当我输入大写字母时,它将与while语句一起进行。我知道我必须使用ignoreCase语句,但是我不知道如何。先感谢您。

public class Aaa {
    AQAConsole2016 console = new AQAConsole2016();
    Random random = new Random();
    int boardSize;
    boolean moveIsValid;

    char [][] board;
    int move;
    char choice;
    String playerName="Human";
    String player2="Computer";
    boolean exit=false;
    public Aaa() {

        boardSize = 6;

        do {
            displayMenu();
            choice = getMenuChoice(playerName);
            switch (choice) {
            case 'p' : playGame(playerName, boardSize);
            break;
            case 'e' : playerName = getPlayersName();
            break;
            case 'c' : boardSize = changeBoardSize();
            break;
            case 'm' : Multiplayer( boardSize,playerName,player2);
            break;
            case 'r' :readBoard(board,boardSize);
            break;
            case 'q' : Quit();


            }
        }while (choice!='p'||choice!='e'||choice!='c'||choice!='m'||choice!='r'||choice!='q');
    }
    void Quit(){
        while (choice=='q'){
            exit=true;
        }

最佳答案

只需使用Character#toLowerCase()即可。

choice = Character.toLowerCase(getMenuChoice(playerName));

10-05 20:36
查看更多