Java error "Dimensions expected after this token" or " '[' expected " can occur while creating array elements or allocating memory using the keyword new. If the square brackets [] are not used properly, you can get this error message.
See the code below:
int myArray[]=new int{10,20,30,40};
Here this is a syntax error. You have to put square brackets [] after new int. To initialize an array the correct code would be:
int myArray[]=new int[]{10,20,30,40};
or just
int myArray[]={10,20,30,40};
See the code below:
int myArray[]=new int{10,20,30,40};
Here this is a syntax error. You have to put square brackets [] after new int. To initialize an array the correct code would be:
int myArray[]=new int[]{10,20,30,40};
or just
int myArray[]={10,20,30,40};
0 comments:
Post a Comment