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];
         int[][] matrixSum = 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 muliplied as follows");
         int[][] matrixProduct = muliplyMatrix(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[][] muliplyMatrix(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[j][i];
             }
         }
         return outcomeMatrix;
     }
 }

HW7.6的更多相关文章

  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. Python:使用threading模块实现多线程编程

    转:http://blog.csdn.net/bravezhe/article/details/8585437 Python:使用threading模块实现多线程编程一[综述] Python这门解释性 ...

  2. 【leetcode】Divide Two Integers (middle)☆

    Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...

  3. Tomcat多次部署

    http://blog.csdn.net/knityster/article/details/6300804

  4. snoopy(强大的PHP采集类) 详细介绍

    Snoopy是一个php类,用来模拟浏览器的功能,可以获取网页内容,发送表单,可以用来开发一些采集程序和小偷程序,本文章详细介绍snoopy的使用教程. Snoopy的一些特点: 抓取网页的内容 fe ...

  5. linux查看历史命令history

    在linux下,我们有可能需要查看最近执行过的命令(历史命令),我们可以进行如下操作: # 显示使用过的所有历史命令 $ history # 显示最近使用的5个命令 $ history 5 我们可以通 ...

  6. [模拟]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 ...

  7. C语言不是C++的严格子集

    C语言是C++的子集吗?C++是在C语言的基础上扩展而来并包含所有C语言的内容吗? 回复: 从实用角度讲,C++属于C语言的一个超集,基本上兼容ANSI C.但是从编译角度上讲,C语言的有些特性在C+ ...

  8. Java Web开发 之小张老师总结EL、JSP、Servlet变量

    EL 11 JSP 9 Servlet JSP类别 pageContext pageContext * 作用域 pageScope pageContext.getAttribute() * reque ...

  9. Qt:QT右键菜单

    Qt QTableView 上加右键弹出菜单, 并复制选中的单元格内容到剪贴板中 http://wenku.baidu.com/view/c51cfb63cf84b9d528ea7a29.html h ...

  10. 【HDOJ】4366 Successor

    基本思路是将树形结构转换为线性结构.然后,所求即为一个区间内大于abi的最大的loy指向的ID.将结点按照abi降序排序,注意abi可能相等.然后,使用线段树单点更新,区间查询可解. /* 4366 ...