HW7.6
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]; int[][] matrixSum = 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 muliplied as follows"); int[][] matrixProduct = muliplyMatrix(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[][] muliplyMatrix(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[j][i]; } } return outcomeMatrix; } }
HW7.6的更多相关文章
- 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 ...
随机推荐
- memmove 和 memcpy的区别
memcpy和memmove()都是C语言中的库函数,在头文件string.h中,作用是拷贝一定长度的内存的内容,原型分别如下:void *memcpy(void *dst, const void * ...
- N-Queens leetcode java
题目: The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two que ...
- java jdk自带程序分析(内存分析/线程分析)
周末看到一个用jstack查看死锁的例子.昨天晚上总结了一下jstack(查看线程).jmap(查看内存)和jstat(性能分析)命令. 1.1.Jstack 1.1 jstack能得到运行jav ...
- java 串口通信 代码
下面是我自己实现的串口接收的类,串口发送比较简单,就直接发送就可以了.下面的这个类可以直接使用. package com.boomdts.weather_monitor.util; import ja ...
- ANDROID_MARS学习笔记_S01_011ProgressBar
文档是这样来设置样式 <ProgressBar android:layout_width="wrap_content" android:layout_height=" ...
- SQLite数据类型详解
一.存储种类和数据类型: SQLite将数据值的存储划分为以下几种存储类型: 复制代码代码如下: NULL: 表示该值为NULL值. INTEGER: 无符号整型值. R ...
- P38、面试题3:二维数组中的查找
题目:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 首先选取数组中右上角的数字 ...
- 当当开源sharding-jdbc,轻量级数据库分库分表中间件
近期,当当开源了数据库分库分表中间件sharding-jdbc. Sharding-JDBC是当当应用框架ddframe中,从关系型数据库模块dd-rdb中分离出来的数据库水平分片框架,实现透明化数据 ...
- MySQL数据库服务器安装标准
MySQL数据库服务器安装标准 (1).BIOS优化,阵列配置 1.1:关闭CPU节能,因为服务器品牌众多,BIOS设置不相同,主要是关闭CPU节能,如C1,DELLR730,已经智能设置,直接有个p ...
- bzoj1079: [SCOI2008]着色方案
ci<=5直接想到的就是5维dp了...dp方程YY起来很好玩...写成记忆化搜索比较容易 #include<cstdio> #include<cstring> #inc ...