Java Array multidimensional Arrays declaration

Question

What is the output of the following code?

public class Main {

  public static void main(String[] args) {
    int[][] r = new int[2]; 
    int[] x = new int[]; 
    int[][] y = new int[3][]; 
    int[][] z = {{1, 2}}; 
    int[][] m = {{1, 2}, {2, 3}}; 
    int[][] n = {{1, 2}, {2, 3}, }; 
  }/* www  .j  ava2 s.  c  om*/
}


int[][] r = new int[2]; //Type mismatch: cannot convert from int[] to int[][]
int[] x = new int[]; //Variable must provide either dimension expressions or an array initializer
int[][] y = new int[3][]; //OK
int[][] z = {{1, 2}}; //OK
int[][] m = {{1, 2}, {2, 3}};//OK 
int[][] n = {{1, 2}, {2, 3}, }; //OK



PreviousNext

Related