testintegermatrix.java

来自「此源码为机械工业出版社出版的《Java语言程序设计》第三版所配套的书中所有源代码」· Java 代码 · 共 42 行

JAVA
42
字号
// TestIntegerMatrix.java: Test matrix operations involving
// integer values
public class TestIntegerMatrix
{
  // Main method
  public static void main(String[] args)
  {
    // Create Integer arrays m1, m2
    Integer[][] m1 = new Integer[5][5];
    Integer[][] m2 = new Integer[5][5];

    // Intialize Integer arrays m1 and m2
    for (int i=0; i<m1.length; i++)
      for (int j=0; j<m1[0].length; j++)
      {
        m1[i][j] = new Integer(i);
      }

    for (int i=0; i<m2.length; i++)
      for (int j=0; j<m2[0].length; j++)
      {
        m2[i][j] = new Integer(i+j);
      }

    // Create instances of IntegerMatrix
    IntegerMatrix im1 = new IntegerMatrix(m1);
    IntegerMatrix im2 = new IntegerMatrix(m2);

    // Perform integer matrix addition, and multiplication
    IntegerMatrix im3 = (IntegerMatrix)im1.addMatrix(im2);
    IntegerMatrix im4 = (IntegerMatrix)im1.multiplyMatrix(im2);

    // Display im1, im2, im3, im4
    System.out.println("m1 + m2 is ...");
    GenericMatrix.printResult(im1, im2, im3, '+');

    System.out.println("\nm1 * m2 is ...");
    GenericMatrix.printResult(im1, im2, im4, '*');
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?