【发布时间】:2014-03-12 10:28:27
【问题描述】:
是否可以使用 Math.random() 命令从数组中调用随机行,或者实际上是否有另一种方法?抱歉,如果这有一个明显的答案,但我对编程完全陌生。我的代码如下:
final float line_positions[][] = new float[][] {
//X coordinate of line, Y Coordinate of hole
}
{ 600, 0.5f },
{ 900, 0.3f },
{ 1200, 0.2f },
{ 1500, 0.3f },
{ 1800, 0.1f },
{ 2100, 0.4f },
{ 2400, 0.5f }
};
......
int temp_score = 0;
for (int i = 0; i < line_positions.length; i++) {
float y = line_positions[i][Y] * ScreenHeight();
float x = ScreenX((int) line_positions[i][X] * ScreenWidth() * 0.0015f);
}
【问题讨论】:
-
所以你想让你的
i被一个随机数替换?但仍然循环检索所有line_positions?
标签: java android arrays random