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 ...
随机推荐
- uva 10051
将每一个分解为六个两面的 简单地dp 回溯输出路径..... #include <cstdio> #include <cstring> #include <cmath&g ...
- html5移动web开发实战必读书记
原文 http://itindex.net/detail/50689-html5-移动-web 主题 HTML5 一.配置移动开发环境 1.各种仿真器.模拟器的下载安装 http://www.mob ...
- console中应用MFC类的方法
1.添加#include <afx.h>或者<afxwin.h> 这时会报错1>c:\program files\microsoft visual studio 8\vc ...
- HDU4647+贪心
/* 贪心. 题意:给定一些点 一些边 点和边都有价值.现在A B 选点.求A-B的maxVal 思路:分割边.边的1/2分给两个端点. 如果这两个点被同一个人取,则ok:否则 做减法也行,对题意无影 ...
- photoshop:模仿-广告放射背景
模仿对象:图片大小960*400 过程: 1.新建文档,大小为:960*800 2.选择渐变工具,黑白从上往下渐变 3.滤镜->扭曲->波浪,参考设置 4.滤镜->扭曲->极坐 ...
- ScrollView can host only one direct child 解决
主要是ScrollView内部只能有一个子元素,即不能并列两个子元素,所以需要把所有的子元素放到一个LinearLayout内部或RelativeLayout等其他布局方式让后再在这个layout外部 ...
- Spring个人总结
编写Spring第一个程序 Spring是一种开源框架,通过使用它可以大大降低企业应用程序的复杂性.Spring是一种非常完善的框架,几乎涉及WEB开发中的每一层,但是在开发中通常使用Spring开发 ...
- [POJ 2420] A Star not a Tree?
A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4058 Accepted: 200 ...
- [NOI2005] 维修数列
1500: [NOI2005]维修数列 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 8397 Solved: 2530 Description In ...
- Java [leetcode 24]Swap Nodes in Pairs
题目描述: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1-& ...