This answer is based mostly on the title of the question. If you provide more information, we may be able to help a little bit more.
There are a few minor issues in the code that lead to it not working.
Firstly, any time you loop through multidimensional arrays, You'll want to make sure the inner loop uses the correct limit. tissue.length refers to the length of the outer array but there is no guarantee that each inner array in the 2d array (ie. tissue[0].length returns the length of an array and tissue[1].length may return a different value). So we'll first replace the inner loop limiter with tissue[k].length.
for(int k = 0; k < tissue.length ; k++){
for(int l = 0 ; l < tissue[k].length ; l++){
if(tissue[k][l] == ' '){
tissue[k][l] = tissue[i][j];
tissue[k][l] = temp;
return;
}
}
}
Next issue I see is the swap. The code you have essentially looks for the first space in any array and inserts the value at i,j but you don't put anything into index i,j. what Elliot mentioned was that the two lines inside the if statement both replace tissue[k][l] with the same value, the one stored at tissue[i][j]. Instead, we'll change the first line to tissue[i][j] = tissue[k][l] to perform the swap. So we end up with the follow method which swaps the first space character in the first string it finds with the character at i,j.
public static void moveTo(char[][] tissue, int i, int j){
char temp = tissue[i][j];
for(int k = 0; k < tissue.length ; k++){
for(int l = 0 ; l < tissue[k].length ; l++){
if(tissue[k][l] == ' '){
tissue[i][j] = tissue[k][l];
tissue[k][l] = temp;
return;
}
}
}
}
' 'twice with the character attissue[i][j]? What is this supposed to do?tempandtissue[i][j]contain the same value. Therefore, no swap occurs inside theif()block.