集册 Java实例教程 写代码做矩阵对角线和

写代码做矩阵对角线和

欢马劈雪     最近更新时间:2020-01-02 10:19:05

574
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
写代码做矩阵对角线和

public class Main {//来 自 时代Java - N o w  J a v a . c o m

  public static void main(String args[]) throws Exception {

    int sumD1 = 0;

    int mRow = 5;

    int mCol = 5;

    int[][] Array = new int[mRow][mCol];

    for (int r = 0; r < Array.length; r++) {

      for (int c = 0; c < Array[r].length; c++) {

        Array[r][c] = r * c;


      }

    }

    // Matrix printing block

    for (int r = 0; r < Array.length; r++) {

      for (int c = 0; c < Array[r].length; c++) {

        System.out.print(Array[r][c] + 
展开阅读全文