0

Nested for-loop.

I'm trying to initialize an array from an object I'm creating. However, I keep getting this error message: /Squarelotron.java:21: error: incompatible types: int cannot be converted to int[][] int[][] ring = squarelotron[x][j]; ^ Why, then am I getting this error? Here's a link to my code: https://code.sololearn.com/c9VypHQF73P8/#java. According to the compiler, the error is on/starts from line 22. Any assistance would be very much appreciated.

1st Apr 2020, 1:27 PM
Jezaniah Apraku
Jezaniah Apraku - avatar
5 Answers
0
You are trying to initialize a 2D array with "a single element" of a 2D array.
1st Apr 2020, 2:32 PM
CarrieForle
CarrieForle - avatar
0
So that means that squarelotron[x][j] is a single element?
1st Apr 2020, 2:49 PM
Jezaniah Apraku
Jezaniah Apraku - avatar
0
Yes. squarelotron is an array. sauarelotron[x][j] is a single element.
1st Apr 2020, 2:51 PM
CarrieForle
CarrieForle - avatar
0
Alright. I thought the loop would initialize the array with the first row of squarelotron[][]. I'll try initializing it the long way round and see if that brings good results.
1st Apr 2020, 2:54 PM
Jezaniah Apraku
Jezaniah Apraku - avatar
0
But ultimately, my goal was to create a ring taking the first and last rows of squarelotron and the values along the side (imagining the squarelotron as a matrix might help you understand what I'm saying).
1st Apr 2020, 2:57 PM
Jezaniah Apraku
Jezaniah Apraku - avatar