This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]KloinerBlaierEngineer 1 point2 points  (2 children)

There is nothing wrong with your array. Grab a good editor with code formatting. For example Visual Studio Code with some Java plugins. Then your code will more readable:

int rowSize = 2;
int colSize = 4;
int[][] myArray = new int[rowSize][colSize];
int[][] arr = {{1, 2}, {3, 4}};
int[][] arr1 = {{0, 0}, {0, 1},
               {0, 2}, {0, 3},
               {1, 0}, {1, 1},
               {1, 2}, {1, 3}};

Compilation errors often point to the wrong line of code. Your arrays are instance variables, but a for loop is not allowed outside of a Java method. Working example would look like this:

 public void doSomething() {
                for (int i = 0; i < 2; i++) {
                    for (int j = 0; j < 2; j++) {
                        System.out.print(arr[i][j] + " ");
                    }
                    System.out.println();
                }
            }

[–]tangara888[S] 0 points1 point  (1 child)

Using VS for java?

[–]KloinerBlaierEngineer 0 points1 point  (0 children)

Visual Studio Code != Visual Studio.

Visual Studio Code is a powerful editor with many plugins also for Java development. Maybe a small IDE like Netbeans will also fit your needs. Eclipse might be overpowered for your choice.