Outside of any method, I did static String wordNames = new String[ 99 ] ; Inside main(), I did wordNames[ 0 ] = "Zero" ; wordNames[ 1 ] = "One" ; ... The nitpicker said "You have declared the array. You have not initialized it. Initialize the arrays when they are declared. Use a static initializer." I thought that 'static String wordNames' was the declaration, and that ' = new String[ 99 ] ;' was the initialization, then the 'wordNames[ 0 ] = "Zero" ;' was the assignment? I understand initializing an array when declaring it, as a style issue to keep things together. I don't understand where the lines are between declaration/initialization/assignment, or how it's not static...???
there is an easier (and much shorter) way to declare an array with multiple objects... if you already know what will be in the array (the strings), then you can declare them all at the same time (hint). when you declare the static array, go ahead and fill it... i do not want to give too much away, but if you use the shorter method, you will not need to use new String[ xx ]; ... thus you will not need to use wordNames[ x ]; for each one.
Hi Dean, The link that Michael gave will definatley guide you for how to write the initialization of the array. Declaring I think is the part where you write: static String wordNames = new String[ 99 ] ; but at that time the size of the array is initialized to 99 and the actual initializations to what goes in the array would be when you write: wordNames[ 0 ] = "Zero" ; wordNames[ 1 ] = "One" ; ... As to the difference between initialization and assignments, well I don't think there is much of a difference other than the initialization is usually the first assignment to the variable that you write. Such as: int x = 1 ; (declaration and initialization/assignment) x = 5 ; (assignment) Hope this makes sense because I am not sure I am explaining myself well! Michael's link will lead you to your answer for the assignemnt
"Happiness is a way to Travel, <b>Not</b> a Destination" -- Unknown
To expand a bit on Amber's excellent explanation: A static initializer is just a bit of language that initializes an array (i.e., puts elements into it) at the same time as the array's declaration. (I suspect that's why the term "static" is used here: initialization isn't drawn out over time.) So when you write String wordnames = new String[ 99 ]; you're just declaring an array of 99 strings; nothing has been put into it as yet. Initializing must then happen later, string by string: I don't know the Javaspeak term for this, but I would call it "dynamic" initializing, since it happens incrementally. And of course, the link Michael mentions has the skinny on this.