Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: Help with Arrays
|
Posted: Nov 14, 2003 10:57 AM
|
|
Two more things:
The myArrayX = i; was probably an accident, but just for clarification, since myArrayX was declared as an array of double, this doesn't make any sense. You could assign myArrayX to refer to another array of double, or to null, but not to a single integer (or even float) value. Of course, there is no problem with assigning elements of of the array (as you do later on), eg. myArray[1] = 1.0; .
> This is just basic addition since you are using ints you > can either create a temp variable or create a private int > variable and then you say temp = x[0] + x[1] +...+x[n-1]
It looks like it was doubles actually, so you'll need a double for the sum. (Ignoring for the sake of simplicity the fact that when summing a particular data type, it is usually safer to use a larger data type for the sum (eg. sum ints into a long or a BigInteger), to avoid overflow problems).
|
|