-1

I know there is a syntax error here, but why?

public class Practice_1 {

    public static void main(String[] args) {

        int[3][3] Array={{11,22,33},{44,55,66},{77,88,99}};

        for (int i=0 ; i<3 ; i++)
        {
            for (int j=0 ; j<3 ; j++)
            {

              System.out.println("Array["+i+"]["+j+"]  store value is"+Array[i][j]);

            }   
        }
    }
}
femtoRgon
  • 32,893
  • 7
  • 60
  • 87
  • possible duplicate of [How to initialize an array in Java?](http://stackoverflow.com/questions/1938101/how-to-initialize-an-array-in-java) – femtoRgon Apr 09 '15 at 22:15

3 Answers3

1

In Java, you don't specify the size of the array dimensions in the type. Here, the dimensions are implied in the array initializer anyway. Remove the 3s from the declaration of the array.

int[][] Array={{11,22,33},{44,55,66},{77,88,99}};

As an aside, in Java, variables are typically declared to start with a lowercase character. It's not an error, but Array would typically be declared with the name array.

rgettman
  • 176,041
  • 30
  • 275
  • 357
0
int[3][3] Array={{11,22,33},{44,55,66},{77,88,99}};   //wrong way to declare array

change to

int[][] Array={{11,22,33},{44,55,66},{77,88,99}};

Java Docs

Note:Please follow java naming convention start variable with lower case or camelCase

singhakash
  • 7,891
  • 6
  • 31
  • 65
0

Your problem is in your array definition. Instead of using

int[3][3] Array={{11,22,33},{44,55,66},{77,88,99}}; 

You should be using

int Array[3][3] = {{11,22,33},{44,55,66},{77,88,99}}; 

In java, you must place an array's size on it's name definition, rather than the type definition. In this case, a size could be omitted altogether, but following your current design, that will work.

In addition, your variable names, by convention, are normally camel-cased, with first words being lower cased, and following words being upper cased. Normally, class names are written as you wrote your Array variable, which could lead to confusion.

DripDrop
  • 994
  • 1
  • 9
  • 18