【习题29】

作者: Xplorist | 来源:发表于2017-04-17 20:55 被阅读12次

【程序29】
题目:求一个3*3矩阵对角线元素之和

package com.share.test_21_30;

public class Test29 {
    public static void main(String[] args) {
        test();
    }
    public static void test(){
        int[][] a=new int[3][3];
        int count=0;
        for(int i=0;i<a.length;i++){
            for(int j=0;j<a[i].length;j++){
                count++;
                a[i][j]=count;
            }
        }
        System.out.println(a[0][0]+a[0][2]+a[1][1]+a[1][1]+a[2][0]+a[2][2]);
    }
}

相关文章

网友评论

    本文标题:【习题29】

    本文链接:https://www.haomeiwen.com/subject/wokxzttx.html