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 ...
随机推荐
- Quartz任务调度快速入门(转)
概述 了解Quartz体系结构 Quartz对任务调度的领域问题进行了高度的抽象,提出了调度器.任务和触发器这3个核心的概念,并在org.quartz通过接口和类对重要的这些核心概念进行描述: ●Jo ...
- onClick(View) of type new View.OnClickListener(){} must override a superclass method
原地址:http://blog.csdn.net/aeolus1019/article/details/8014798 Android开发过程中代码错误报错如下: - implements andro ...
- Python 异常结构
http://flyheaven.blog.163.com/blog/static/7401172201193085243920/ 1.Python内建异常体系结构 The class hierarc ...
- C++中怎么获取类的成员函数的函数指针?
用一个实际代码来说明. class A { public: staticvoid staticmember(){cout<<"static"<<endl;} ...
- android 使用Activity做窗口弹出(模拟Dialog)
我们下面使用Activity,模拟一个dialog: 首先看布局: <?xml version="1.0" encoding="utf-8"?> & ...
- Java知识大全
http://blog.csdn.net/zhangerqing/article/details/8245560
- live555源码研究(五)------DynamicRTSPServer类
一.类DynamicRTSPServer作用 1,提供RTSP服务 二.类DynamicRTSPServer继承关系图
- java:复写equals实例
class User { String name; int age; /* *比较过程思路: *1.两个对象指向位置相同,那么他们就相等,return后跳出函数,不再往下执行 *2.指向位置不同,有3 ...
- *IntelliJ IDEA配置Hibernate
为IntelliJ IDEA安装Hibernate插件
- C#+SQL数据库备份和还原
使用前要导入SQLDMO.dll(在com组件中导入Microsoft SQLDMO Object Library即可) /// /// DbOper类,主要应用SQLDMO实现对Microsoft ...