So my problem is that I can not switch elements of a 2D array like I can do in a single variable Instead of switching array elements, they are being constantly rewritten ...
for (int column = 0; column & lt; m [0]; length; column ++) {Shufcol = (int) (math.random () * 4); Temp = column; Println (shufcol); (Int line = 0; line & lt; m.length; line ++) {temp = row; Meter [row] [temporary] = meter [row] [column]; M [row] [column] = m [row] [shaffcoll]; M [row] [temp] = m [row] [shufkol]; }} Input array (3x4) {{1 2 3} {1 4 5 6} {7 8 9}}
Output array {{2 3 2} {5 5 6 5} {8 8 9}}
If you are curious about math.random , then it is only a random column between 0 To generate 3 again the issue to switch from 3 is that why is it just writing the elements again and not switching them?
I do not fully understand what you want to achieve at the end (because you have not told ), But I think, if you read this piece of code again:
temp = row; Meter [row] [temporary] = meter [row] [column]; M [row] [column] = m [row] [shaffcoll]; M [row] [temp] = m [row] [shufkol]; Many times and try to execute it with a piece of paper and pen, you will get a mistake.
Comments
Post a Comment