我的MovePath()
方法中的int dice
需要获取GetRollDice()
中int step
的值> 方法。
我正在使用 Java。
我该怎么做?
public static int getRollDice(){
int[] diceStep= {-2,-1,1,2,3};
int randomStep = new Random().nextInt(diceStep.length);
int step = diceStep[randomStep];
return step;
}
public static int MovePath(Integer dice,Integer path){
// int dice = step value from GetRollDice
//Get Initial Path
//Next path = roll dice value + initial path
return path;
}
最佳答案
您只需调用您的方法,无需重新声明dice
:
public static int MovePath(Integer dice,Integer path){
dice = getRollDice();
//Get Initial Path
//Next path = roll dice value + initial path
return path;
}
<小时/>
请记住,Java 中的所有内容都是对 Object
的引用...除了基本类型(如 int
、short
等)之外的所有内容...
参见What is the difference between Integer and int in Java?了解更多相关信息。
关于java - 如何从另一个方法的返回方法中获取参数的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33899722/