1. import java.util.Scanner;
  2.  
  3. public class Solution
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner input = new Scanner(System.in);
  8. int[][] matrix1 = new int[3][3];
  9. int[][] matrix2 = new int[3][3];
  10. System.out.print("Enter matrix1: ");
  11. for(int i = 0; i < 3; i++)
  12. for(int j = 0; j < 3; j++)
  13. matrix1[i][j] = input.nextInt();
  14. System.out.print("Enter matrix2: ");
  15. for(int i = 0; i < 3; i++)
  16. for(int j = 0; j < 3; j++)
  17. matrix2[i][j] = input.nextInt();
  18. input.close();
  19.  
  20. System.out.println("The matrices are added as follows");
  21. int[][] matrixSum = addMatrix(matrix1, matrix2);
  22.  
  23. System.out.println(matrix1[0][0] + " " + matrix1[0][1] + " " + matrix1[0][2] +
  24. " " + matrix2[0][0] + " " + matrix2[0][1] + " " + matrix2[0][2] +
  25. " " + matrixSum[0][0] + " " + matrixSum[0][1] + " " + matrixSum[0][2]);
  26. System.out.println(matrix1[1][0] + " " + matrix1[1][1] + " " + matrix1[1][2] +
  27. " + " + matrix2[1][0] + " " + matrix2[1][1] + " " + matrix2[1][2] +
  28. " = " + matrixSum[1][0] + " " + matrixSum[1][1] + " " + matrixSum[1][2]);
  29. System.out.println(matrix1[2][0] + " " + matrix1[2][1] + " " + matrix1[2][2] +
  30. " " + matrix2[2][0] + " " + matrix2[2][1] + " " + matrix2[2][2] +
  31. " " + matrixSum[2][0] + " " + matrixSum[2][1] + " " + matrixSum[2][2]);
  32. }
  33.  
  34. public static int[][] addMatrix(int[][] a, int[][] b)
  35. {
  36. int[][] outcomeMatrix = new int[3][3];
  37. for(int i = 0; i < 3; i++)
  38. for(int j = 0; j < 3; j++)
  39. outcomeMatrix[i][j] = a[i][j] + b[i][j];
  40. return outcomeMatrix;
  41. }
  42. }

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. Educational Codeforces Round 5 A

    Problem A:http://codeforces.com/contest/616/problem/A A. Comparing Two Long Integers 果然还是我太天真了(长整数比较 ...

  2. Django 后台搭建

    # Django settings for gameadmin project. DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Nam ...

  3. JAVA面试题:String 堆内存和栈内存

    java把内存划分为两种:一种是栈(stack)内存,一种是堆(heap)内存 在函数中定义的一些基本类型的变量和对象的引用变量都在栈内存中分配,当在一段代码块定义一个变量时,java就在栈中为这个变 ...

  4. [模拟]ZOJ3480 Duck Typing

    题意:给了一坨...按题目意思输出就好了... 给一组案例 begin class d class c:d class b:c class a:b def d.m def d.n call a.m e ...

  5. Agri Net POJ1258 && Constructing Roads POJ2421

    题意,在给出的图中,使用最小花费的边,使这个图仍然连通. #include <cstdio> #include <algorithm> #include <cstring ...

  6. binary 和 varbinary

    固定长度或可变长度的 Binary 数据类型. binary [ ( n ) ] 长度为 n 字节的固定长度二进制数据,其中 n 是从 1 到 8,000 的值.存储大小为 n 字节. varbina ...

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

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

  8. MySQL数据库服务器安装标准

    MySQL数据库服务器安装标准 (1).BIOS优化,阵列配置 1.1:关闭CPU节能,因为服务器品牌众多,BIOS设置不相同,主要是关闭CPU节能,如C1,DELLR730,已经智能设置,直接有个p ...

  9. Smallest unused ID

    http://www.codewars.com/kata/smallest-unused-id Description: Hey awesome programmer! You've got much ...

  10. 理解Java对象序列化(二)

    关于Java序列化的文章早已是汗牛充栋了,本文是对我个人过往学习,理解及应用Java序列化的一个总结.此文内容涉及Java序列化的基本原理,以及多种方法对序列化形式进行定制.在撰写本文时,既参考了Th ...