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 ...
随机推荐
- 编写你的第一个 Django 程序 第2部分
原地址:http://django-chinese-docs.readthedocs.org/en/latest/intro/tutorial02.html 本教程上接 教程 第1部分 . 我们将继续 ...
- 学习笔记:shared_ptr陷阱
条款1:不要把一个原生指针给多个shared_ptr管理 int* ptr = new int; shared_ptr<int> p1(ptr); shared_ptr<int> ...
- 【BZOJ 2618】 2618: [Cqoi2006]凸多边形 (半平面交)
2618: [Cqoi2006]凸多边形 Description 逆时针给出n个凸多边形的顶点坐标,求它们交的面积.例如n=2时,两个凸多边形如下图: 则相交部分的面积为5.233. Input 第一 ...
- ios loading视图动画(模仿58同城)
最近看了58同城的加载视图,感觉很不错,如下图: 所以想模仿写一个,下载58同城的app,解压,发现它用的是图片来实现的动画效果, 并不是绘制出来的,所以这就相对简单些了,其实整个动画的逻辑不复杂,无 ...
- win7 64bit下最新Apahe2.4.18+php7.0.2+MySQL5.7.10配置
原文:win7 64bit下最新Apahe2.4.18+php7.0.2+MySQL5.7.10配置 一.说明 以前配置apache+php+mysql都是参考网上的,一般都没有什么问题.最近公司有个 ...
- JavaScript DOM高级程序设计 4.3控制事件流和注册事件侦听器--我要坚持到底!
一.事件流 我们通过下面一个实例,进行说明. <body> <h1>Event Flow</h1> <ul id="nav"> &l ...
- hadoop博客 oschina
http://my.oschina.net/Xiao629/blog?catalog=449279
- poj 1850 code(组合数学)
题目:http://poj.org/problem?id=1850 题意:按给定的规则给字母编号. 一个很简单的题目,但是却做了好久.................................. ...
- Oracle数据库生成UUID
从Data Ghost的blog得知,原来可以用Oracle来生成UUID,做法很简单,如下: select sys_guid() from dual; 数据类型是 raw(16) 有32个字符.
- bzoj3294
感觉自己就是不怎么擅长计数的问题 设f[k,i,j]表示前k种颜色占据了i行j列的方案 g[k,i,j]表示第k种颜色占据了i行j列的方案,注意要减去并没占据满i行j列的情况 然后转移就很好写了 像这 ...