gpt4 book ai didi

java - 错误: incompatible types return scores; required: int found: ArrayList

转载 作者:行者123 更新时间:2023-12-01 11:42:08 26 4
gpt4 key购买 nike

//Class declaration of Player class
public class Player
{
/*--------------- Data Fields ---------------------------------------
Attributes of the class
*/
private String name;
private int playerId;
private int bestScore;
private static int numberOfPlayers = 0;
private ArrayList<Integer> scores = new ArrayList<Integer>();

//Create set method for setScores
public void setScore(int score)
{
scores.add(score);
}

//Create get method for getScores
public int getScores()
{
return scores;
}
}

我尝试寻找解决方案,但似乎找不到。我被要求为一名猜谜游戏的玩家存储 5 个分数。我只是想知道我应该在 getScore 方法中放入什么。

最佳答案

看这里,问题就在这里:

public int getScores()
{
return scores;
}

您正在从声明返回 int 的方法返回 ArrayList

关于java - 错误: incompatible types return scores; required: int found: ArrayList<Integer>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29440129/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com