import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);
         int[][] matrix1 = new int[3][3];
         int[][] matrix2 = new int[3][3];
         System.out.print("Enter matrix1: ");
         for(int i = 0; i < 3; i++)
             for(int j = 0; j < 3; j++)
                 matrix1[i][j] = input.nextInt();
         System.out.print("Enter matrix2: ");
         for(int i = 0; i < 3; i++)
             for(int j = 0; j < 3; j++)
                 matrix2[i][j] = input.nextInt();
         input.close();

         System.out.println("The matrices are added as follows");
         int[][] matrixSum = addMatrix(matrix1, matrix2);

         System.out.println(matrix1[0][0] + " " + matrix1[0][1] + " " + matrix1[0][2] +
                 "     " + matrix2[0][0] + " " + matrix2[0][1] + " " + matrix2[0][2] +
                 "     " + matrixSum[0][0] + " " + matrixSum[0][1] + " " + matrixSum[0][2]);
         System.out.println(matrix1[1][0] + " " + matrix1[1][1] + " " + matrix1[1][2] +
                 "  +  " + matrix2[1][0] + " " + matrix2[1][1] + " " + matrix2[1][2] +
                 "  =  " + matrixSum[1][0] + " " + matrixSum[1][1] + " " + matrixSum[1][2]);
         System.out.println(matrix1[2][0] + " " + matrix1[2][1] + " " + matrix1[2][2] +
                 "     " + matrix2[2][0] + " " + matrix2[2][1] + " " + matrix2[2][2] +
                 "     " + matrixSum[2][0] + " " + matrixSum[2][1] + " " + matrixSum[2][2]);
     }

     public static int[][] addMatrix(int[][] a, int[][] b)
     {
         int[][] outcomeMatrix = new int[3][3];
         for(int i = 0; i < 3; i++)
             for(int j = 0; j < 3; j++)
                 outcomeMatrix[i][j] = a[i][j] + b[i][j];
         return outcomeMatrix;
     }
 }

HW7.5的更多相关文章

  1. HW7.18

    public class Solution { public static void main(String[] args) { int[][] m = {{1, 2}, {3, 4}, {5, 6} ...

  2. HW7.17

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  3. HW7.16

    import java.util.Arrays; public class Solution { public static void main(String[] args) { int row = ...

  4. HW7.15

    public class Solution { public static void main(String[] args) { double[][] set1 = {{1, 1}, {2, 2}, ...

  5. HW7.14

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  6. HW7.13

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  7. HW7.12

    import java.util.Scanner; public class Solution { public static void main(String[] args) { double[] ...

  8. HW7.11

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  9. HW7.10

    public class Solution { public static void main(String[] args) { int[][] array = new int[3][3]; for( ...

  10. HW7.9

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

随机推荐

  1. IDEA 运行maven命令时报错: -Dmaven.multiModuleProjectDirectory system propery is not set

    在file-setting里面,找到maven的设置: 先加入一个环境变量 然后配置一个JVM的参数: -Dmaven.multiModuleProjectDirectory=$M2_HOME OK ...

  2. 在linux下,查看一个运行中的程序, 占用了多少内存

    1. 在linux下,查看一个运行中的程序, 占用了多少内存, 一般的命令有 (1). ps aux: 其中  VSZ(或VSS)列 表示,程序占用了多少虚拟内存. RSS列 表示, 程序占用了多少物 ...

  3. cocos2d-x 添加 libLocalStorage 库...

    说明:由于libLocalStorage底层是用sqlite实现的,所以要先按上面官方提供的集成sqlite的文档,将sqlite添加到项目中. 重点还是android的编译配置,加粗的是需要增加的配 ...

  4. nginx面试题

    1.Nginx是如何实现高并发的 service nginx start之后,然后输入#ps -ef|grep nginx,会发现Nginx有一个master进程和若干个worker进程,这些work ...

  5. 省市区 Mysql 数据库表

    1.查省SELECT * FROM china WHERE china.Pid=02.查市SELECT * FROM chinaWHERE china.Pid=3300003.查区SELECT * F ...

  6. 212. Word Search II

    题目: Given a 2D board and a list of words from the dictionary, find all words in the board. Each word ...

  7. WCF 传输的序列化

    // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService”.[ServiceContract]public interface IService{ [O ...

  8. while ((ch = getchar()) != EOF)中ch定义为char还是int型?cin、scanf等如何结束键盘输入

    2013-07-09 18:55:42 EOF是文件的结束符,具体可以作为文本文件的结束符,也可以作为键盘输入char类型数据时的结束符.对于不同的系统,EOF的定义可能不同,一般定义为-1.因为ch ...

  9. 蓝牙(2)用BluetoothAdapter搜索蓝牙设备示例

    注意在搜索之前要先打开蓝牙设备 package com.e.search.bluetooth.device; import java.util.Set; import android.app.Acti ...

  10. git clone 出错SSL certificate problem, verify that the CA cert is OK.

    先调用这个 export GIT_SSL_NO_VERIFY=true 之后再执行git clone