我对Java相当陌生,希望有人能够帮助我。我正在尝试创建一个链接列表以比较中奖号码和玩家号码

最佳答案

您应该在PLAYER中修复getNext函数,以便它返回一个彩票对象,该对象可以分配给彩票中matchs()函数中的next对象。

当前,它具有一个整数参数并返回一个整数,但是您可以将其用作
您的matchs()中的next = next.getNext()

我想这就是你想要的

public PLAYER getNext() {
      return pNext;
}


编辑:
为了简单起见,我省略了if语句。

public void matches() {
    PLAYER currentPlayer = pHead;
 // PLAYER pNext; remove this, since you are not using pNext in the if statments

    do{
        int count = 0;
   //   PLAYER next = pNext; also remove this for the same reason
        for(int i = 0; i<6; i++) {
            for(int j = 0; j< 6; j++) {
                //check the winning numbers in currentPlayer instead of a null object pNext
                if (win.getWinningNumbers(j) == currentPlayer.getNumbers(i)) {
                    count++;
                }
            }
        }
        // next = next.getNext(); remove for the same reason as above
        // since you are using currentPlayer to check if the player wins, you shouldto modify current player
        currentPlayer = currentPlayer.getNext();
        } while(currentPlayer != null ); //check if currentPlayer is not null
    }

关于java - 链表getNext()和while(next!= null);问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60529759/

10-12 04:08