如题!
package 矩阵2; public class JuZheng { public static void main(String args[]) { int array[][] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; int max = array[0][0]; int min = array[0][0]; int sum1 = 0; int sum2 = 0; System.out.println("输出矩阵为:"); for (int i = 0; i < 3; i++) { sum1 += array[i][i]; sum2 += array[i][3 - i - 1]; for (int j = 0; j < 3; j++) { System.out.print(array[i][j] + " "); if (array[i][j] > max) { max = array[i][j]; } if (array[i][j] < min) { min = array[i][j]; } } System.out.println(); } System.out.println("最大元素和最小元素的和为:" + (max + min)); System.out.println("两对角线的和分别为:" + sum1 + "和" + sum2); } }
输出矩阵为: 1 2 3 4 5 6 7 8 9 最大元素和最小元素的和为:10 两对角线的和分别为:15和15