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 ...
随机推荐
- 技术贴 本地代码与svn关联教程 svn upgrade问题解决
背景: 以前从SVN上下载了项目源码,可是SVN抽风了,死活不显示我修改了哪些代码 自己从别人机器上搞来了项目源码,没有svn版本控制,但是svn上面有这些源码 如上两种,我想关联一下,把我本地的代码 ...
- asp网站通用后台代码设计
main2.css: a:link {color: #333333; text-decoration: none}a:visited {color: #000000; text-decoration: ...
- Fiddler 日志
Fiddler 日志(Logging) 在开发扩展插件及编写FiddlerScript时对调试程序非常有用. 1.输出日志 在FiddlerScript脚本中,你可以这样输出输出日志: Fiddler ...
- 中国首个 SaaS 模式的云告警平台安卓版 APP 上线
今年一月底,国内首个 SaaS 模式的云告警平台 OneAlert 正式发布了 iOS 版 App 客户端,今天上午,安卓版 App 客户端也正式上线了!每个安卓用户,无需电脑,都可以通过手机全程跟踪 ...
- C++开源跨平台类库集
在如下的库支持下,开发的系统可以很方便移植到当前大部分平台上运行而无需改动,只需在对应的平台下 用你喜欢的编译器 重新编译即可 经典的C++库 STLport-------SGI STL库的跨平台 ...
- _CrtIsValidPointer 问题
从微软站点: 检查指针有效性下面的示例使用 _CrtIsValidPointer 验证给定的内存范围对于读或写是否有效. _ASSERTE(_CrtIsValidPointer( address, s ...
- 我见过的 Objective-C, 讲的最通俗易懂的入门教程....
http://www.cnblogs.com/mjios/category/454764.html ---- 给力...
- Android EditText控件行尾为表情时的BUG
今天处理项目上的一个诡异BUG,贴吧Android客户端发贴框是支持表情文字混排的,但是当发贴框的行内容末尾为表情时,尝试在表情后插入文字,就悲剧了:文字其实写进去了,但是不会显示出来.研究了一下,发 ...
- ubuntu 解决依赖问题
安装aptitude包管理器 然后用aptitude安装 sudo aptitude install ***
- javacript序列化表单数据
在前端开发时,用到表单交互的比较多,在我们实现一些异步操作数据时,表单数据的序列化就显得尤为重要了.下面我们一起来看看如何进行序列化. 如,我们在进行提交表单时,地址栏里会显示这样的东东:name=z ...