Last active
January 11, 2016 20:41
-
-
Save ckob/40f6df4e574c4f76c6d4 to your computer and use it in GitHub Desktop.
Transpose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| public class Program { | |
| public static void main (String args[]) { | |
| int[][] o = new int[][]{ | |
| { 1, 20, 10 }, | |
| { 6, 3, 18 } | |
| }; | |
| int[][] d = new int[o[0].length][o.length]; | |
| for (int i = 0; i < o.length; i++) { | |
| for (int j = 0; j < o[i].length; j++) { | |
| d[j][i]=o[i][j]; | |
| } | |
| } | |
| System.out.println(Arrays.deepToString(o)); | |
| System.out.println(Arrays.deepToString(d)); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| public class Program { | |
| public static void main (String args[]) { | |
| int[][] o = new int[][]{ | |
| { 1, 20, 10 }, | |
| { 6, 3, 18 }, | |
| { 30, 2, 7 } | |
| }; | |
| System.out.println(Arrays.deepToString(o)); | |
| int tmp; | |
| for (int i = 0; i < o.length; i++) { | |
| for (int j = i+1; j < o[i].length; j++) { | |
| tmp = o[i][j]; | |
| o[i][j]=o[j][i]; | |
| o[j][i]=tmp; | |
| } | |
| } | |
| System.out.println(Arrays.deepToString(o)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment