1,数组顺时针旋转90度 1 2 //数组顺时针旋转90° 3 //列变行(正 0列-->0行,1列-->1行...) 4 //行变列(反 0行-->length-1列,1行-->length-2列...) 5 public class ...
1,数组顺时针旋转90度
1 2 //数组顺时针旋转90° 3 //列变行(正 0列-->0行,1列-->1行...) 4 //行变列(反 0行-->length-1列,1行-->length-2列...) 5 public class Rotate { 6 public static void getRotate(int[][] x) { 7 8 int[][] b = new int[x[0].length][x.length]; 9 // 转换10 for (int i = 0; i < x.length; i++) {11 for (int j = 0; j < x[i].length; j++) {12 b[j][x.length - i - 1] = x[i][j];13 }14 }15 // 输出16 for (int i = 0; i < b.length; i++) {17 for (int j = 0; j < b[i].length; j++) {18 System.out.print(b[i][j] + " ");19 }20 System.out.println();21 }22 23 }24 // 测试25 public static void main(String[] args) {26 int[][] a = {{ 0, 1 ,2 }, 27 { 0, 1 ,5 }, 28 { 1, 1 ,6 }, 29 { 1, 2 ,5 },30 { 1, 2 ,5 }31 };32 getRotate(a);33 }34 }
原标题:Java典型题目 长期更新
关键词:JAVA
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。