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. 宏 #,##,_ _VA_ARGS_ _

    宏里面使用: 一.#  转为字符串 #define PSQR(x) printf("the square of" #x "is %d.\n",(x)*(x)) ...

  2. Android 调用系统的拍相程序进行录像

    xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...

  3. web页面浮动回到顶部功能和浮动广告

    实现测试浮动回到顶部 法一:用js实现<%@ Page Language="C#" AutoEventWireup="true" CodeBehind=& ...

  4. 命名空间“System.Web.Mvc”中不存在类型或命名空间名称“Ajax”(是否缺少程序集引用?)

    解放方法 右键打开这个项目引用System.Web.Mvc,如图: 将复制本地的值改为True,英文的话应该是Copy Local,这样就解决了上面的报错问题.

  5. 命令行添加用户的“作为服务登录”权利(添加Windows用户的时候,门道不是一般的多)good

    1.打开控制台(“开始”|“运行”中输入:MMC) 2.“文件”菜单|“添加删除管理单元”|“添加...”|选“安全模板”|“关闭”. 3.在“C:\Windows\Security\template ...

  6. MAC下编译FFMPEG

    1.下载ffmpeg,我使用xcode自带的git下载. 或者直接下载压缩包: 2.下载gas-preprocessor脚本 https://raw.github.com/mansr/gas-prep ...

  7. 91. Decode Ways

    题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: ' ...

  8. Android性能优化典范 - 第2季

    Google发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的缩放,缓 ...

  9. Apache James搭建内网邮件服务器

    Apache James搭建内网邮件服务器 极客521 | 极客521 2014-08-21 148 阅读 java 大概之前两个礼拜的日子,讨论会介绍了关于了.net内网邮件服务器的搭建.所以自己也 ...

  10. xml格式化

    Vim怎么格式化xml,完全不会,vim的缩进也搞不明白