HW7.6

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的更多相关文章
- HW7.18
public class Solution { public static void main(String[] args) { int[][] m = {{1, 2}, {3, 4}, {5, 6} ...
- HW7.17
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW7.16
import java.util.Arrays; public class Solution { public static void main(String[] args) { int row = ...
- HW7.15
public class Solution { public static void main(String[] args) { double[][] set1 = {{1, 1}, {2, 2}, ...
- HW7.14
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW7.13
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW7.12
import java.util.Scanner; public class Solution { public static void main(String[] args) { double[] ...
- HW7.11
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW7.10
public class Solution { public static void main(String[] args) { int[][] array = new int[3][3]; for( ...
- HW7.9
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
随机推荐
- hdu 3537 Daizhenyang's Coin 博弈论
详见:http://www.cnblogs.com/xin-hua/p/3255985.html 约束条件6 代码如下: #include<iostream> #include<st ...
- hdu 4649 Professor Tian 反状态压缩+概率DP
思路:反状态压缩——把数据转换成20位的01来进行运算 因为只有20位,而且&,|,^都不会进位,那么一位一位地看,每一位不是0就是1,这样求出每一位是1的概率,再乘以该位的十进制数,累加,就 ...
- 意外发现,VC断点可加在构造函数的左括号上
CTestApp::CTestApp() { // 断点加在这里,然后可单步进入CTestApp的父类CWinApp的构造函数进行调试! ; } 并且在CWinApp的构造函数的左括号上,可进一步进入 ...
- Java比较器对数组,集合排序一
数组排序非常简单,有前辈们的各种排序算法,再加上Java中强大的数组辅助类Arrays与集合辅助类Collections,使得排序变得非常简单,如果说结合比较器Comparator接口和Collato ...
- linux的终端,网络虚拟终端,伪终端(转)
blog.csdn.net/todd911/article/details/8025540 Linux上许多网络服务应用,如l2tp.pptp.telnet,都用到了伪终端.有朋友在问这方面的概念 ...
- 主机头部分 www有和无是有区别的
关于主机部分www的问题: case 1: frontend web_service bind *:80 bind *:443 ssl crt /etc/haproxy/cert.pem acl ww ...
- android SharedPreferences 使用
除了SQLite数据库外,SharedPreferences也是一种轻型的数据存储方式,它的本质是基于XML文件存储key-value键值 对数据,通常用来存储一些简单的配置信息.其存储位置在/dat ...
- ogg实现oracle到sql server 2005的同步
一.源端(oracle)配置1.创建同步测试表create table gg_user.t01(name varchar(20) primary key);create table gg_user.t ...
- 使用SAE部署Flask,使用非SAE flask版本和第三方依赖包的方法
目前SAE的Flask的版本为0.7,但是我从学习开始的flask版本就已经是0.10了,而且一些扩展都是使用的0.10以后的from flask.ext.特性进行引入的.所以需要修改SAE的环境. ...
- sublime text格式化插件
sublime text 软件其实是自带格式化插件的,但是它默认的格式化插件,不太好用,且没有快捷键(虽然自己可以设置). 其默认的格式化是在 Edit -> Line -> Re ...