如何编写静态值返回方法

时间:2017-12-08 18:51:19

标签: java methods return boolean

它不会返回,并希望返回一些东西 它出什么问题了 ? 为什么当我想从这个布尔方法返回时,它要求我返回 我刚刚在方法体

中设置了回报
  public static Boolean winner(char[][] board) {
                if ((board[0][0] == board[0][1] && board[0][0] == board[0][2])
                        || (board[0][0] == board[1][1] && board[0][0] == board[2][2])
                        || (board[0][0] == board[1][0] && board[0][0] == board[2][0])
                        || (board[2][0] == board[2][1] && board[2][0] == board[2][2])
                        || (board[2][0] == board[1][1] && board[0][0] == board[0][2])
                        || (board[0][2] == board[1][2] && board[0][2] == board[2][2])
                        || (board[0][1] == board[1][1] && board[0][1] == board[2][1])
                        || (board[1][0] == board[1][1] && board[1][0] == board[1][2])) {
                    return true;
                } else if (true) {
                    for (int i = 0; i < board.length; i++) {
                        for (int j = 0; j < board[0].length; j++) {
                            if (board[i][j] == 'O' || board[i][j] == 'X') {
                                System.out.println("Game Over ");
                                return false;
                            }
                        }
                    }

                }

            }

1 个答案:

答案 0 :(得分:1)

否则if(true)是不必要的。你刚回来,如果大的if是真的。除此之外,当嵌入在两个循环中的if为真时,您只返回第二个块。你需要在循环后返回一些东西。