Which of the following statements correctly initializes a two-dimensional array in Java?

  • int[][] arr = new int[3][3];
  • int[][] arr = {{1,2,3}, {4,5,6}, {7,8,9}};
  • int[][] arr = new int[2][];
  • int[][] arr = new int[][3];
In Java, a two-dimensional array can be initialized using the curly braces {} with values enclosed in them. Option 2 correctly initializes a 2D array with values, while the other options are incorrect or incomplete.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *