1 package FushiExam;
 2 
 3 public class Text_29 {
 4 
 5     public static void main(String[] args) {
 6         // 求3*3矩阵对角线元素之和
 7         int sum=0;
 8         int[][] arr= {{1,2,3},{4,5,6},{7,8,9}};
 9         for(int i=0;i<3;i++) {
10             for(int j=0;j<arr.length;j++) {
11                 if(i==j)
12                 sum=sum+arr[i][j];
13             }
14         }
15         System.out.println(sum);
16     }
17 
18 }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-11
猜你喜欢
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-12
相关资源
相似解决方案