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 ...
随机推荐
- DWR
DWR(Direct Web Remoting)是一个用于改善web页面与Java类交互的远程服务器端Ajax开源框架,可以帮助开发人员开发包含AJAX技术的网站.它可以允许在浏览器里的代码使用运行在 ...
- uva 125
floyd 算法 如果存在无数条路 则存在a->a的路 a->b的路径数等于 a->i 和 i->b(0=<i<=_max) 路径数的乘积和 #includ ...
- 一分钟明白 VS manifest 原理
什么是vs 程序的manifest文件 manifest 是VS程序用来标明所依赖的side-by-side组建,如ATL, CRT等的清单. 为什么要有manifest文件 一台pc上,用一组建往往 ...
- POJ 3191 The Moronic Cowmpouter(进制转换)
题目链接 题意 : 将一个10进制整数转化为-2进制的数. 思路 :如果你将-2进制下的123转化为十进制是1*(-2)^2+2*(-2)^1+3*(-2)^0.所以十进制转化为-2进制就是一个逆过程 ...
- ubuntu12 开机自动转到命令行
命令: sudo gedit /etc/default/grub 找到这一行 GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"改成 GRUB_CM ...
- easyui源码翻译1.32+API翻译全篇导航 (提供下载源码)
前言 EasyUI每个组件都会有 属性.方法.事件 属性 所有的属性都定义在jQuery.fn.{plugin}.defaults里面.例如,对话框属性定义在jQuery.fn.dialog.defa ...
- nginx配置负载均衡与反向代理
#给文件夹授权 1 chown -R www:www /usr/local/nginx #修改配置文件vim nginx.conf 1 2 3 4 5 6 7 8 9 10 11 12 13 ...
- ANDROID_MARS学习笔记_S01_002View、监听器初步
一.View.监听器介绍 二.在Activity中获取view和设置属性,设置button的监听器 1.activity_main.xml <LinearLayout xmlns:android ...
- Android日期时间选择器实现以及自定义大小
本文主要讲两个内容:1.如何将DatePicker和TimePicker放在一个dialog里面:2.改变他们的宽度: 问题1:其实现思路就是自定义一个Dialog,然后往里面同时放入DatePick ...
- 程序员的自我修养(2)——计算机网络(转) good
相关文章:程序员的自我修养——操作系统篇 几乎所有的计算机程序,都会牵涉到网络通信.因此,了解计算机基础网络知识,对每一个程序员来说都是异常重要的. 本文在介绍一些基础网络知识的同时,给出了一些高质量 ...