View Full Version : "Not a statement" error?! Help needed with simple java.
http://www.geocities.com/eradistheman/java.png
Why am I getting a "Not a statement" error when I try to compile here? I'm just trying to make a no-arg constructor that sets the field numbers[][] to those numbers...
Fou-Lu
12-10-2008, 10:54 PM
I believe the syntax you have used for you're arrays is only available when you are declaring it:
private int[][] nums = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}};
I do not believe you can use the curly braces syntax once its been declared and initialized. I may be mistaken on that; it has been awhile since I've done java programming.
Roelf
12-11-2008, 01:37 PM
youre not mistaken. This will work:
public class Fun {
private static int numbers[][] = {{4,7,3},{2,10,2},{4,5,6}};
public static void main(String[] args) {
Fun f = new Fun();
}
public Fun() {
System.out.println(numbers[1][1]);
}
}
If I Were A Boy
12-12-2008, 09:08 AM
Yes ! Array initializations should always be done during its declaration.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.