Can i take input inside curly bracket

int arr[][]={{sc.nextInt(); ,sc.nextInt();},{1,2,3}}
can we do like this???

No you can’t take like this.
It is basically a syntax error.
For taking input in 2D array, loops are used.

but i tred and it worked fine

Yeah it will work fine but it will only work for input of 2x3 2DArray.It will not work for MxN 2D arrays.

why?? what is the logic behind it!!

int arr[][]={
{sc.nextInt(),sc.nextInt()},
{1,2,3}
};
Above code declares 2*3 Array,i.e. 2 Rows and 3 Columns.
Now,Lets dry run your above code Line By Line.

Initially sc.nextInt(); is asking an input,Lets take 100 as Input
then second sc.nextInt(); is asking an input, Lets take 200 as Input
So,we have two inputs for first row.Hence,First Row looks like:{100,200}
Then We have another row without any Inputs.hence Second Row looks like:{1,2,3}
So the Complete 2D array becomes [100,200],[1,2,3].
For better clarification,Please try to display your 2D Array.
I hope this resolves your doubt.

I don’t understand the problem i am getting the desired matrix with 2 columns in 1st row and columns in second row

*3 columns in second row

please help your replies are very hope giving

Hi, thanks for the appreciation
The idea is basically,
If you have to take input for a 2D Matrix of size NxM(N Rows,M Columns);As It will have NxM Elements.
For that You Basically have two choices
Either to Take input one by one N*M inside #curly brackets# which is practically tedious.
Or
You take input using nested loops(for inside for).
and we think The Second method is much much superior.
Please hit like if it resolves your Doubt.