Run ID:63835
提交时间:2024-01-19 21:24:04
/** * 沿对角线打印 * 同一层级的横坐标和纵坐标之和相等 * * @param */ private static void slash(int[][] matrix) { int cols = matrix[0].length; int rows = matrix.length; //层级 for (int l = 0; l < cols + rows - 1; l++) { int sum = l; for (int i = 0; i < rows; i++) { int j = sum - i; if (i >= 0 && i < rows && j >= 0 && j < cols) { System.out.print(matrix[i][j] + " "); //System.out.print("i: " + i + " j: " + j + " "); } } System.out.println(); } }