宠物小精灵游戏。无法返回数组JAVA

时间:2017-05-15 02:35:26

标签: java methods return

public static int wildPokemon(int opponentstats[] , int  rattataStats[] , int  geodudeStats[] , int  pidgeyStats[])
{
rattataStats = new int[]{27,42,35};
geodudeStats = new int[]{35,45,80};
pidgeyStats = new int[]{39,33,33};

System.out.println(".");
Pause(1000);
System.out.println(".");
Pause(1000);
System.out.println(".");
Pause(1000);   

Random wildPokemon = new Random();
int opponent = (wildPokemon.nextInt(3));
while(true)
{
if(opponent == 0)
{
 System.out.println("You have come across a wild Rattata!!!");
 rattataStats[0] = opponentstats[0];
 rattataStats[1] = opponentstats[1];
 rattataStats[2] = opponentstats[2];
 return opponentstats;

}
else if(opponent == 1)
{
  System.out.println("You have come across a wild Geodude!!!");
 geodudeStats[0] = opponentstats[0];
 geodudeStats[1] = opponentstats[1];
 geodudeStats[2] = opponentstats[2];
 return opponentstats;

}
else if(opponent ==-2)
{
  System.out.println("You have come across a wild Pidgey!!!");
 pidgeyStats[0] = opponentstats[0];
 pidgeyStats[1] = opponentstats[1];
 pidgeyStats[2] = opponentstats[2];
 return opponentstats;
}
}
}

我很失落和沮丧。为什么我不能回到对手的位置,而且它的内部价值也是如此!谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

声明该方法返回int。

您尝试返回的变量的类型为int []。

所以要么将返回类型更改为int数组,要么返回单个int值(不是数组!)。