to output all elements of square matrix in a spiral

You couldn’t use a variable in your loop already exist before your method :

int j = m + 1 - k;
//  ^--------------------------------------Already exist
for (int i = k + 1; i < m + 1 - k; i++) {

for (int j = m - k; j > k; j--) {
//       ^---------You can't declare a variable already exist, 
                   //you can just use it or initialize it

So instead use this without int j:

 for (j = m - k; j > k; j--) {


//                   ^-----The i is not exist so you have to 
                         //create it and inisialize it so you can use it

Browse More Popular Posts

Leave a Comment