2条回答 默认 最新
- allway2 2021-04-19 19:03关注
package sample; public class CsdnArray { public static void main(String[] args) { int[][] array = new int[5][6]; for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[0].length; j++) { array[i][j] = i * i - (j - i) * (j - i) + 10; System.out.print(array[i][j] + " "); } System.out.println(); } System.out.println(); // getMaximumOfEveryRow () for (int i = 0; i < array.length; i++) { int max = Integer.MIN_VALUE; for (int j = 0; j < array[i].length; j++) if (array[i][j] > max) max = array[i][j]; System.out.println("Maximum of row " + i + " = " + max); } // getMinimumOfEveryColumn for (int i = 0; i < array[0].length; i++) { int min = Integer.MAX_VALUE; for (int j = 0; j < array.length; j++) if (array[j][i] < min) min = array[j][i]; System.out.println("Minimum of column " + i + " = " + min); } } }
10 9 6 1 -6 -15
10 11 10 7 2 -5
10 13 14 13 10 5
10 15 18 19 18 15
10 17 22 25 26 25Maximum of row 0 = 10
Maximum of row 1 = 11
Maximum of row 2 = 14
Maximum of row 3 = 19
Maximum of row 4 = 26
Minimum of column 0 = 10
Minimum of column 1 = 9
Minimum of column 2 = 6
Minimum of column 3 = 1
Minimum of column 4 = -6
Minimum of column 5 = -15
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报