我的计划是创建一个只有两个值的数组,即{0,0},因为我想更改它的值以模拟坐标如何移动。 当随机数分配给 x 时,我想将坐标移动到 (0,1),
假设我有一行 if 循环,
if(x=0){ //I would change the value from {0,0} to {0,1} }
我尝试用这种方式编写代码,
public static int x = 0;
public static int y = 0;
public static void randomWalk(int [] moving_point) {
int r = ThreadLocalRandom.current().nextInt(4);
if(r == 0) {
moving_point[x,y] = moving_point[x,y+1];
}
}
但这是不正确的,
这是可能的事情吗?如何? 谢谢!
最佳答案
最里面的代码必须更改为:
移动点[1] = 移动点[1] + 1;
1
为您提供 moving_point 数组中“y”位置的索引,但不会修改您的字段。
关于java - 如何将 {0,0} 放入数组中并在满足 if 语句时更改它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57790917/