1

I am learning about 2D arrays but I am stuck on this issue and I don't know what I am doing wrong. I have this so far:

    double[][] arr = new double[3][2];

    arr[0] = {1.0,1.0,1.0,1.0,1.0}; // this doesn't work

but that seems to be wrong for some reason, I get

 Array Initializer is not allowed here

what I am trying to do is make the first column of the first row equal to: 1.0,1.0,1.0,1.0,1.0

I can do it by declaring another array and then setting it equal to the first column of the first row:

    double [] arr1 = {1.0,1.0,1.0,1.0,1.0};
    double[][] arr = new double[3][2];

    arr[0] = arr1; // this seems to work

My question is how can I add the values manually without having to first declare an array and setting it equal to it, or without having to use a for loop.

edit: The answers of the the previous questions were too complicated for me to understand. Thanks for the answers guys, this helped me a lot.

lokilindo
  • 682
  • 5
  • 17

0 Answers0