I am trying to, inside a method, set a temporary variable equal to a predefined variable and modify the temporary variable and return it as an output. However along the way the predefined variable gets modified as well which causes an issue when I try to compare the modified variable to the original variable later. I have tried setting the original variable to final and tried to make the temporary variable new to no avail. I'm not sure how to sort out this bug, the code is like follows:
private static int[][] scanmap(int[][] map) {
int[][] fillmap = mapzeros(map); //goal is to replace the map with zeros
printMap(map);
//checkboarder
fillmap = mapboarder(fillmap, map);
//keepadj
fillmap = checkAdj(fillmap,map);
return fillmap;
}
in the mapzeros(map) method where the bug takes place
private static int[][] mapzeros(int[][] map) {
int[][] tempmap = map; //temporary variable
for (int j =0; j < map.length; j++){
for (int i =0; i < map[j].length; i++){
tempmap[j][i] = 0;//why is this setting map[j][i] to 0???
printMap(map); //shows the map
}
}
return tempmap;
}