编写程序完成矩阵的乘法运算

要求:程序运行后要求用户分别输入两个矩阵的行数和列数,然后判断两个矩阵是否可以相乘,如果可以相乘,则计算矩阵相乘后的结果,并按矩阵的格式输出;若不能相乘,则提示用户矩阵不相容,并退出程序。

提示:一个2行3列的矩阵可以用一个二维数组表示:int matrixA[2][3]。此外,必须要知道什么是矩阵相乘。矩阵相乘的概念如下图所示:
在这里插入图片描述
代码块如下:

/**
 * 
 * @author 芳芳
 *
 */
import java.util.Scanner;

public class matrixMultiplication {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		//定义三个行列不超过20的矩阵
		int[][] matrix1 = new int[20][20];
		int[][] matrix2 = new int[20][20];
		int[][] matrix3 = new int[20][20];
		System.out.println("Please input the lines and rows of the two matrices in order");
		System.out.println("the line of matrix1:");
		int m1 = scanner.nextInt();
		System.out.println("the row of matrix1:");
		int n1 = sca
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值