问题数组赋值 [英] Problem with array assignment

查看:95
本文介绍了问题数组赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've got the following problem with an array assignment...

我有在Global.java一个全球性的float数组声明...

I've got a global float array in Global.java declared as...

公共静态浮动camObjCoord [] =新的浮动[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);
    }

我把这种方法是这样的...

I call this method like so...

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

推荐答案

您有我在那里++。所以认为这

You have i++ in there. So consider this

Global.cam[i] = highx;
DebugPrint("cube i = " + cam[i]);
i++;

否则,你参考下一个每次。

Otherwise, you're referencing the NEXT one every time.

这篇关于问题数组赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆