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. 团体程序设计天梯赛-练习集L1-004. 计算摄氏温度

    L1-004. 计算摄氏温度 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈建海 给定一个华氏温度F,本题要求编写程序,计算对应的 ...

  2. uva 10739

    dp 只有三个操作  当str[i] != str[j] 时 dp(i, j) = min(dp(i+1, j), dp(i+1, j-1), dp(i, j-1)) #include <ios ...

  3. 盘点 OSX 上最佳的 DevOps 工具

    [编者按]对于运维人员来说,他们往往需要各种各样的工具来应对工作需求,近日 Dustin Collins 通过「The Best DevOps Tools on OSX」一文对 OSX 平台上的工具进 ...

  4. Topo图

    http://blog.csdn.net/youfangyuan/article/details/8367398 http://joshuaxiao.iteye.com/blog/2224120 ht ...

  5. Maven Source jar

    http://blog.csdn.net/symgdwyh/article/details/4407945

  6. zoj 3640 Help Me Escape 概率DP

    记忆化搜索+概率DP 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

  7. hdu 4664 Triangulation 博弈论

    看到这题时,当时还不会做,也没搞懂sg函数,于是狠狠的钻研了下博弈论,渐渐的知道了sg函数…… 现在在来做这题就很容易了,1A 打表容易发现在80左右的时候就出现循环节了 代码如下: #include ...

  8. maven新建Spring MVC + MyBatis + Oracle的Web项目中pom.xml文件

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  9. 【转】windows c++获取文件信息——_stat函数的使用

    _stat函数的功能 _stat函数用来获取指定路径的文件或者文件夹的信息. 函数声明 int _stat( const char *path, struct _stat *buffer ); 参数: ...

  10. Android:控件ProgressBar进度条

    各种进度条属于 ProgressBar的子类 设置style: 环形进度条   style="?android:attr/progressBarStyleLarge" 横向进度条, ...