Began to learn java. Compiled such code:

int a[]; int b[]; int c[]; b = c = [3]; System.out.print(b + " " + c); 

There was an error in the penultimate line:

 Syntax error on token "=", Expression expected after this token 

How to fix?

  • Damn, that's why so perverted? Is it really impossible to create a two-dimensional array, or at least in each array, immediately specify its dimension? After all, the second will not only simplify the code for perception, but also reduce it =) - Salivan

2 answers 2

or so

  int b[]; int c[]; b = c = new int [3]; 

we create 2a arrays B and C, and then we initialize them by selecting them with the size of 3 cells. And B and C will be links to one array.

  • > giving them the size of 4 @Gorets cells, did you want to say "3 cells"? - Nofate
  • out of three. You specify the size. And the indices will be 0, 1, 2 - Anton Feoktistov
  • Exactly out of three - Gorets

b = c = [3];

How to fix?

And what did you even try to do?

I suppose to create 2 arrays on the 1st element equal to 3.

 int b[] = new int[] { 3 }; int c[] = new int[] { 3 }; System.out.print(b[0] + " " + c[0]);