Scenario: a two-dimensional array can store tabular data, and can also be used to add various operations according to subscript index, and the key operation of the image is based on a two-dimensional array of matrix Operations.
Create two-dimensional array int arr[][] = new int[][]{{1,2,3},{4,5,6},{7,8,9}}; System.out.println ("column before and After:");//output two-dimensional array printarray (arr); int arr2[][] = new int[arr.length][arr.length];//adjust array row and column data for ( int i = 0; I < arr.length; I++) {for (int j = 0; J < arr.length; j + +) {arr2[i][j] = arr[j][i];}} System.out.println ("after row and column Intermodulation:");p Rintarray (arr2);} private static void PrintArray (int[][] Arr) {//traversal array for (int i = 0; i < arr.length; i++) {for (int j = 0; J < Arr.leng Th J + +) {//non-newline output array element System.out.print (arr[i][j]+ "");} NewLine System.out.println ();}}
Note: two-dimensional arrays are traversed using a double for loop, and the new array and the Row-and-column index interchange of the original array are assigned elements to enable the operation of swapping rows and columns in a two-dimensional array
This article is from the "it rookie" blog, make sure to keep this source http://mazongfei.blog.51cto.com/3174958/1906996
Swaps the rows and columns in a two-dimensional array