提问人:Alice333 提问时间:2/17/2023 更新时间:2/17/2023 访问量:36
如何访问带有参数的方法?
How to access a method with parameters?
问:
我正在使用 Java 在 IntelliJ 中创建一个骰子游戏作为项目,现在我在 Game 类中有一个方法,我想在游戏开始时重置骰子杯。因此,我创建了一个名为 resetDiceCup() 的方法和一个名为 startGame() 的方法。 现在,我在 startGame() 中收到错误“Identifier expected”,我认为这与我在 resetDiceCup() 中使用的参数有关。 有什么办法可以解决这个问题吗?
public class Game{
public void startGame() {
resetDiceCup( int doublets, int numOfDoublets);
System.out.println("Willkommen zu diesem Würfelspiel. Los geht´s!");
String[] playerNames = Print.multipleAnswers("Please insert the name of a player.");
player = new Player[playerNames.length];
for (int i = 0; i < playerNames.length; i++)
{
player[i] = new Player(playerNames[i]);
}
}
//to "refresh" the DiceCup before every new game
public void resetDiceCup(int doublets, int numOfDoublets) {
int[] result = new int[numOfDices]; //amout of dices in the game as chosen by players
sum = 0;
doublets = 0;
numOfDoublets = 0;
sumWithDoublets = 0;
}
}
答: 暂无答案
下一个:无法使用方法跨类更改变量的值
评论
resetDiceCup( int doublets, int numOfDoublets);
从调用中删除这两个 S(仅在那里,不在方法声明中)。int
startGame