I have this program which takes a 2D array of letters, and scrambles them. However, one line of my code changes a separate array for literally no apparent reason whatsoever?!
Here's the code:
private String[][] words = {{"a", "b", "c"}, {"d", "e", "f"}, {"g", "h", "i"}};
public Scramble()
{
String[] a = words[2];
// At this point, a = {"g", "h", "i"}
words[2][0] = words[0][2];
// After this line, a changes to {"c", "h", "i"}
words[1][2] = words[2][1];
words[2] = words[1];
words[1] = a;
}
Why is it doing this?!