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 ...
随机推荐
- Side by Side Assembly介绍--manifest文件的使用
什么是Side-by-Side Assembly? Side-by-Side Assembly(建称SxS)是微软在Visual Studio 2005(Windows 2000?)中引入的技术,用来 ...
- ajax返回正个页面
- iOS设计模式——委托(delegate)
委托(delegate)也叫代理是iOS开发中常用的设计模式.我们借助于protocol(参考博文:objective-c协议(protocol))可以很方便的实现这种设计模式. 什么是代理? 苹果的 ...
- 发现一个可以在线运行JS代码的网站
平时可以在这里玩 http://jsbin.com/
- HDU 5039 Hilarity
题意:一棵树n个结点,每条边有0.1两种权值,每次询问权值为奇数的路径数目,或者改变某一条边的权值. 分析:这个题目很巧妙低利用了异或和的特性,dfs得到每个点到根结点的权值异或和,然后奇数则为1,偶 ...
- C++ 通过对象方式 、指针方式两种方式去访问成员变量(属性或者方法)
准备 1.在VS中新建一个项目-Viscal C++ ---常规--空项目 2.建立一个.h的头文件 定义一个类 声明其成员(C#中的属性和方法) #include<iostream> # ...
- 在Oracle 11g r2中,EXP无法导出个别空的表
在Oracle 11g r2中,发现传统的exp无法不能导出空的表,上网搜索了一下找到了原因. 主要是Oracle 11g 新增了一个参数:deferred_segment_creation,含义是段 ...
- Android ActionBar通过Tab进行不同的Fragment之间的交换
ActionBar的使用常见于4.0系统,其Tab的使用挺广泛的. 在ActionBar中添加标签(Tabs),每个标签对应的是一个Fragment,点击不同的Tab时,就会切换到对应的Fragmen ...
- Java SE7新特性之try-with-resources语句
try-with-resources语句是一个声明一个或多个资源的 try 语句.一个资源作为一个对象,必须在程序结束之后随之关闭. try-with-resources语句确保在语句的最后每个 ...
- MinHash算法-复杂度待整理
1MinHash简介 传统的hash算法只负责将原始内容尽量均匀随机地映射为一个签名值,原理上相当于伪随机数产生算法.传统hash算法产生的两个签名,如果相等,说明原始内容在一定概率下是相等的:如果不 ...