0

大文字と小文字を無視する方法を教えてください。表示メニューを作成し、小文字を入力すると正しい出力が行われましたが、大文字を入力すると 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;
        }
4

3 に答える 3

2

これにはCharacter#toLowerCase()を使用してください。

choice = Character.toLowerCase(getMenuChoice(playerName));
于 2016-06-04T12:53:14.467 に答える
0

文字を小文字にする方法を使用してみてください

例:

     displayMenu();
     choice = Character.toLowerCase(getMenuChoice(playerName));
     switch (choice) {
于 2016-06-04T12:54:37.393 に答える