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 ...
随机推荐
- Educational Codeforces Round 5 A
Problem A:http://codeforces.com/contest/616/problem/A A. Comparing Two Long Integers 果然还是我太天真了(长整数比较 ...
- Django 后台搭建
# Django settings for gameadmin project. DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Nam ...
- JAVA面试题:String 堆内存和栈内存
java把内存划分为两种:一种是栈(stack)内存,一种是堆(heap)内存 在函数中定义的一些基本类型的变量和对象的引用变量都在栈内存中分配,当在一段代码块定义一个变量时,java就在栈中为这个变 ...
- [模拟]ZOJ3480 Duck Typing
题意:给了一坨...按题目意思输出就好了... 给一组案例 begin class d class c:d class b:c class a:b def d.m def d.n call a.m e ...
- Agri Net POJ1258 && Constructing Roads POJ2421
题意,在给出的图中,使用最小花费的边,使这个图仍然连通. #include <cstdio> #include <algorithm> #include <cstring ...
- binary 和 varbinary
固定长度或可变长度的 Binary 数据类型. binary [ ( n ) ] 长度为 n 字节的固定长度二进制数据,其中 n 是从 1 到 8,000 的值.存储大小为 n 字节. varbina ...
- while ((ch = getchar()) != EOF)中ch定义为char还是int型?cin、scanf等如何结束键盘输入
2013-07-09 18:55:42 EOF是文件的结束符,具体可以作为文本文件的结束符,也可以作为键盘输入char类型数据时的结束符.对于不同的系统,EOF的定义可能不同,一般定义为-1.因为ch ...
- MySQL数据库服务器安装标准
MySQL数据库服务器安装标准 (1).BIOS优化,阵列配置 1.1:关闭CPU节能,因为服务器品牌众多,BIOS设置不相同,主要是关闭CPU节能,如C1,DELLR730,已经智能设置,直接有个p ...
- Smallest unused ID
http://www.codewars.com/kata/smallest-unused-id Description: Hey awesome programmer! You've got much ...
- 理解Java对象序列化(二)
关于Java序列化的文章早已是汗牛充栋了,本文是对我个人过往学习,理解及应用Java序列化的一个总结.此文内容涉及Java序列化的基本原理,以及多种方法对序列化形式进行定制.在撰写本文时,既参考了Th ...