行列互换输出
/* 一;需求:编写程序是二维数组{{1,2,3},{4,5,6},{7,8,9}}行列互换{{1,4,7},{2,5,8}{3,6,9}}方式输出 二:思路:先遍历数组,遍历过只要输出的结果互换就可以了 三:步骤;1.使用嵌套fox循环遍历数组, 2,输出的时候进行对调互换就可以了 */ public class Demo4 { public static void main(String[] args) { int[][] arr = {{1,2,3},{4,5,6},{7,8,9}}; for (int i=0;i<arr.length;i++) { for (int j=0;j<arr[i].length;j++) { System.out.print(arr[j][i]+"\t"); //进行行列互换输出结果 } System.out.println(); } } }
网友留言(0 条)