我在数组赋值时遇到以下问题...
我在 Global.java 中有一个全局 float 组,声明为...
public static float camObjCoord[] = new float[8000];
然后我将填充其内容。
public void addcube(float highx, float lowx, float highz, float lowz){
//Constructing new cube...
System.out.println("f = " + f);
Global.cubes++;
float y = 1.5f;
System.out.println("highx = " + highx + "lowx = " + lowx + "highz = " + highz + "lowz = " + lowz);
//FRONT
Global.camObjCoord[Global.i++] = highx;
System.out.println("cube i = " + Global.i);
}
我这样称呼这个方法......
addcube(-2.0f, 2.0f, -2.0f, 2.0f);
以下是调试打印..
07-13 16:01:16.220: INFO/System.out(4837): highx = -2.0lowx = 2.0highz = - 2.0lowz = 2.0 //This is the values coming in to the class
07-13 16:01:16.220: INFO/System.out(4837): 0.0 //This is the contents of index 0
07-13 16:01:16.220: INFO/System.out(4837): cube i = 1
07-13 16:01:16.220: INFO/System.out(4837): 0.0 //Contents of i 1
07-13 16:01:16.220: INFO/System.out(4837): cube i = 2
07-13 16:01:16.220: INFO/System.out(4837): 0.0 //Contents of i 2
07-13 16:01:16.220: INFO/System.out(4837): cube i = 3
07-13 16:01:16.230: INFO/System.out(4837): 0.0 //Contents of i 3
所以,正如你所看到的.. 当我分配值时,它们只是.. 没有被分配给索引.. 为什么?所有索引均保持等于 0.0
最佳答案
你那里有 i++ 。所以考虑一下这个
Global.cam[i] = highx;
DebugPrint("cube i = " + cam[i]);
i++;
否则,您每次都会引用下一个。
关于java - 数组赋值问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3238690/