I've a little confusion, when we declare & initialize a 2D array in java like given below
int arr[][]={{1,2,3,4},{4,3,2,1}};
This work correct, but when do do the above action like given below
int arr[2][4]={{1,2,3,4},{4,3,2,1}};
Then why it generates an error? Why can't we fix the size of rows and columns and then assign values in same statement? I know that we can do that separately using loops, something like arr[0][0]=345; and so on, but why can't we do it like this?
int arr[4][2]={{1,2,3,4},{4,3,2,1}};
int[][] arrinstead ofint arr[][].