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. 服务器程序源代码分析之三:gunicorn

    服务器程序源代码分析之三:gunicorn 时间:2014-05-09 11:33:54 类别:网站架构 访问: 641 次 gunicorn是一个python web 服务部署工具,类似flup,完 ...

  2. VARCHAR2转换为CLOB碰到ORA-22858错误

    近日工作中发现有一张表的字段类型建错了,本应是BLOB类型却被别人建成了VARCHAR2(200),修改时oracle却提示“ORA-22858 invalid alteration of datat ...

  3. 将ANGULAR与后端请求结合

    简单的结合,却是很多应用的基础.RESTFUL就此而生.瘦服务,富客户. <!DOCTYPE html> <html lang="en" ng-app=" ...

  4. ABC: Always Be Coding——程序员面试必

    本文作者@guitardave24 ">David Byttow 是一名程序员,曾在 Google 和 Square 等公司工作过. 在正文之前,先让我们回答几个简单的问题:第一,你面 ...

  5. spring transactionmanager

    Spring配置文件中关于事务配置总是由三个组成部分,分别是DataSource.TransactionManager和代理机制这三部分,无论哪种配置方式,一般变化的只是代理机制这部分. DataSo ...

  6. Python之数据结构篇

    简介: 数据结构是可以处理一些数据的结构,或者说,他们是用来存储一组相关数据的.在python中有三种内建的数据结构,分别是列表.元组合字典.我们将会学习如何使用它们是编程变得简单. 列表 list是 ...

  7. 再分析 返回值加引用&,const

    本文主要分析,返回&,和返回值加const的作用. 返回& 定义一个数组模板: template<class T>class Array{ enum{size = 100} ...

  8. devfs,proc,udev

    devfs:常用的驱动函数封装 proc:在用户态检查内核状态的机制 udev 和 devfs相比? 一个是用户空间里的,一个运行在内核空间且被2.6以后版本抛弃了

  9. ibeacons社区

    http://www.idropbeacon.com http://www.chinaibeacons.com http://iwebad.com/tag/ibeacon http://www.cng ...

  10. Innodb MVCC源码实现

    1. 概述 MVCC: 即多版本一致性,在事务模型下,使用version控制数据版本,关系型数据库基本都实现了MVCC,以对表数据的读写互不阻塞,增大了并发量. Oracle和MySQL数据库都是使用 ...