이 기사에서는 Java 프로그래밍에서 구현 한 2 차원 배열 전환 기능에 대해 설명합니다. 다음과 같이 참조에 대해 공유하십시오.
/** * 2 차원 배열의 전치 구현 * @author han * */public class transposition_arrays2d_ch6_4 {최종 정적 이중 pi = 3.1415; public static void main (string [] args) { /*statictest st1 = new statictest (); statestest st2 = new statictest (); st1.method2 ( "han");*// ***** 전치에 사용될 2 차원 배열을 정의하십시오 **********/ int arr2d [] [] = {{1,2,3}, {4,5,6}, {7,8,9}}; /***** 새로운 2 차원 배열은 결과를 구축하는 데 사용됩니다. ********//*결과 배열 변수를 먼저 정의하고, 그렇지 않으면 먼저 메모리를 열도록주의하십시오. 그렇지 않으면 주소 통과 일뿐입니다. 두 차선 이름은 실제로 같은 메모리 조각을 가리 키십시오*// 2 차원의 구성이 필요하지는 않습니다. int result_arr [] [] = new int [arr2d.length] []; // 첫 번째 차원 (int i = 0; i <arr2d.length; i ++) {// 두 번째 차원 result_arr [i] = new int [i] .length]; } // int result_arr [] [] = arrays.copyof (arr2d, arr2d.length); // 위의 명령 줄은 작동하지 않습니다! / ****** 전환을위한 2 차원 배열 *******/ for (int x [] : arr2d) {for (int e : x) {system.out.print (e+""); } system.out.println (); } system.out.println (); / ********* 요소 반전 *******/ for (int i = 0; i <arr2d.length; i ++) {for (int J = 0; // core}}/****** 결과 결과 매트릭스에서 결과를 표시 ******/for (int x [] : result_arr) {for (int e : x) {system.out.print (e+""); } system.out.println (); }}} // import java.util.arrays; // public class transfer_arrays2d {/// public static void main (string [] args) {// int arr2d [] = {{1,2,3}, {4,5,6}, {7,8,9}}; // Otherwise, it's just address passing, that is, the two array names actually point to the same piece of memory*/// int result_arr[][]=new int[arr2D.length][];// for(int i=0 ; i<arr2D.length;i++){// result_arr[i]=new int[arr2D[i].length];// }/// // Invert the element// for(int i = 0; i arr2d.length; i ++) {// for (int j = 0; System.out.print (e); //} // system.out.println (); //} //} ///} ///} ///} ////}실행 결과 :
Java 알고리즘에 대한 자세한 내용은이 사이트에 관심이있는 독자들이 주제를 볼 수 있습니다. "Java 데이터 구조 및 알고리즘 자습서", "Java Operation Dom Node Tips 요약", "Java 파일 및 디렉토리 작동 팁 요약"및 "Java Cache Operation Tips의 요약"을 볼 수 있습니다.
이 기사가 모든 사람의 Java 프로그래밍에 도움이되기를 바랍니다.