public class zhuanzhi { public static String[][] zhuanzhi(String[][] arr2D){ String result_arr[][] = new String[arr2D[0].length][arr2D.length]; /*****输出用于转置的二维数组*******/ for (String x[]:arr2D){ for(String e:x){ System.out.print(e+" "); } System.out.println(); } System.out.println(); /*******进行元素倒置******/ for(int i=0 ; i<arr2D.length;i++){ for(int j=0; j<arr2D[i].length;j++){ result_arr[j][i]=arr2D[i][j]; //转置核心 } } for (String x[]:result_arr){ for(String e:x){ System.out.print(e+" "); } System.out.println(); } return result_arr; } public static void main(String[] args) { String[][]arr2D = {{"newid,2.0", "ea7c2512a8f64d8eafdb5b56b0580ae0,3.0", "eaca34c2945d4e3a84529b6bff261db7,1.0", "ef0e2faef0fb4eba8f41e0b9361a15bc,2.0","0c951a332c604da5a6853b28a8b06e55,6.0"}, {"newid,1.0", "ea7c2512a8f64d8eafdb5b56b0580ae0,3.0", "eaca34c2945d4e3a84529b6bff261db7,2.0", "ef0e2faef0fb4eba8f41e0b9361a15bc,1.0", "0c951a332c604da5a6853b28a8b06e55,3.0"}}; zhuanzhi(arr2D); } }
时间: 2024-11-06 13:47:26