数组赋值问题

Ski*_*zit 2 java arrays floating-point

我有一个数组赋值的以下问题...

我在Global.java中有一个全局浮点数组声明为......

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);
    }
Run Code Online (Sandbox Code Playgroud)

我这样称呼这个方法......

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
Run Code Online (Sandbox Code Playgroud)

所以,正如你所看到的......当我分配值时,他们只是......不会被分配给索引..为什么?所有指数保持相等0.0

cor*_*iKa 5

你有i ++.所以考虑一下

Global.cam[i] = highx;
DebugPrint("cube i = " + cam[i]);
i++;
Run Code Online (Sandbox Code Playgroud)

否则,您每次都会引用NEXT.