I have run the following Java code:
import java.util.*;
public class Main {
public static void main(String[] args) {
int[][] arr= {{1,2,3},{4,5,6},{7,8,9}};
int i;
for(i=1;i<arr.length;i++)
arr[i]=arr[i-1];
arr[0]=arr[arr.length-1];
arr[1][1]=7;
System.out.println(arr);
for(i=0;i<arr.length;i++){
for(int j=0;j<arr[i].length;j++){
System.out.printf("%d ",arr[i][j]);
}
System.out.printf("n");
}
}
}
Output is the following:
1 7 3
1 7 3
1 7 3
But my expectation was:
1 2 3
1 7 3
1 2 3
Why does this happen?