This site requires JavaScript, please enable it in your browser!
Greenfoot back
Unknown6415
Unknown6415 wrote ...

2017/6/5

What is wrong with this array?

Unknown6415 Unknown6415

2017/6/5

#
I wrote this array like a saw in an example:
double[] A = new double[5];
            A[0] = -200;
            A[1] = 200;
But when I compile, it shows me an error at " A
Super_Hippo Super_Hippo

2017/6/5

#
The code does not give any errors inside a method, so I guess you put it outside methods. Maybe this does what you want:
double[] a = {-200, 200, 0, 0, 0};
Unknown6415 Unknown6415

2017/6/5

#
I wrote now
double[] P = {
                       {-200, 200, -200},
                       {-200, -200, -200}
                     }
But there is still an error: illegal initializer for double
Super_Hippo Super_Hippo

2017/6/5

#
Try to use
double[][]
and at a semicolon at the end of line 4.
Unknown6415 Unknown6415

2017/6/5

#
Ohh it works! But why is this wrong:
int x = (int) P[0][1]+400
it shows the error at the "1" " array required, but int found " what should I do?
Super_Hippo Super_Hippo

2017/6/5

#
It seems like you are not using the same P as above. You always have to use the correct size of the array.
Unknown6415 Unknown6415

2017/6/5

#
What do you mean by "not the same P as above" ? I only have one "P"
Unknown6415 Unknown6415

2017/6/5

#
ohh wow, I changed every "P" to "Pu" and it worked
Super_Hippo Super_Hippo

2017/6/5

#
Well, it's not like P is forbidden and Pu isn't or something like that. But using your P above and then this line, it didn't give me an error. So I guess you initialized another P somewhere.
Unknown6415 Unknown6415

2017/6/5

#
Well my code is pretty short, and there is no other P, but it doesn't matter anymore, it works Thanks!
You need to login to post a reply.