HW7.5
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]; 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 added as follows"); int[][] matrixSum = addMatrix(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[][] addMatrix(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[i][j]; return outcomeMatrix; } }
HW7.5的更多相关文章
- 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 ...
随机推荐
- C++函数中那些不可以被声明为虚函数的函数
转自C++函数中那些不可以被声明为虚函数的函数 常见的不不能声明为虚函数的有:普通函数(非成员函数):静态成员函数:内联成员函数:构造函数:友元函数. 1.为什么C++不支持普通函数为虚函数? 普通函 ...
- 用CodeViz绘制函数调用关系图(call graph)
CodeViz是<Understanding The Linux Virtual Memory Manager>(at Amazon,下载地址在页尾)的作者 Mel Gorman 写的一款 ...
- 【leetcode】Word Break (middle)
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...
- 【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)
Rotating Scoreboard Description This year, ACM/ICPC World finals will be held in a hall in form of a ...
- 【mysql的设计与优化专题(2)】数据中设计中的范式与反范式
设计关系数据库时,遵从不同的规范要求,设计出合理的关系型数据库,这些不同的规范要求被称为不同的范式,各种范式呈递次规范,越高的范式数据库冗余越小.但是有些时候一昧的追求范式减少冗余,反而会降低数据读写 ...
- eCos中的线程与同步
http://blog.csdn.net/ooaven/article/details/6280018 先看一下eCos线程的创建.控制以及优先级的操作这三个方面的知识,主要是对它的实现方式及API做 ...
- POJ3278——Catch That Cow(BFS)
Catch That Cow DescriptionFarmer John has been informed of the location of a fugitive cow and wants ...
- Linux Shell常用命令手册(Updating)
检查远程端口是否对bash开放: nc -nvv $IP $PORT telnet $IP $PORT 当前任务的前后台切换: Ctrl + z fg 截取变量前5个字符: ${variable:0: ...
- linux bash脚本把A和B文件中有相同ID的B文件的内容输出到文件C
bash脚本把A和B文件中有相同ID的B文件的内容输出到文件C. Aid文件:ID001.1ID032.1ID090.10 Bfilt文件:XX XX XXX ID001.1 XXX999999999 ...
- ubuntu程序安装方法
以前一直使用window,今天安装了一个ubuntu系统(如果有同学也想装,建议装英文版的),因为以前ubuntu系统用的不多,所以安装软件就是一个问题. 就以安装chrome来说吧: 1.在Goog ...