-
Looping Array Elements
Hi,
I'm giving a go at Java and found a problem I'm unable to solve here..
I want to display all the elements in an array. So, I did this:
Code:
public class Goober {
public static void main(String[] args) {
double[] classArray = {23.44, 33.23, 88.66, 34.34, 55.55, 33.44};
classArray = new double[5];
for (int i = 0; i < classArray.length; i++) {
System.out.println(classArray[i]);
}
}
}
The output is this:
0.0
0.0
0.0
0.0
0.0
What is it that I've done wrong?
I'm using OpenJDK 6 on Arch Linux.
-
First you initialize the array with six values and in the next line you overwrite the reference with a new double array of size 5. As you don't fill the new array you get the default values.
-
Jeez.. I feel kinda dumb now.
Think you for the quick reply.
-