tag:blogger.com,1999:blog-694855878384792308.post4173247185296807316..comments2024-03-21T06:26:49.387-07:00Comments on Java67: Matrix Multiplication in Java using Scanner, Class, and Function [Example]javin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-694855878384792308.post-11048572625338628812022-01-22T04:29:16.865-08:002022-01-22T04:29:16.865-08:00HelpfulHelpfulAnonymoushttps://www.blogger.com/profile/07058119145616932807noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-14749028273659786672022-01-04T06:41:17.937-08:002022-01-04T06:41:17.937-08:00public Matrix multiply(Matrix other) {
if ...public Matrix multiply(Matrix other) {<br /> if (this.columns != other.rows) {<br /> throw new IllegalArgumentException("column of this matrix is not equal to row " + "of second matrix, cannot multiply");<br /> }<br /> int[][] product = new int[this.rows][other.columns];<br /> // int sum = 0;<br /> for (int i = 0; i < this.rows; i++) {<br /> for (int j = 0; j < other.columns; j++) {<br /> for (int k = 0; k < other.rows; k++) {<br /> product[i][j] += data[i][k] * other.data[k][j];<br /> }<br /> // product[i][j] = sum;<br /> }<br /> }<br /> return new Matrix(product);<br /> }Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-44660731900584374032017-09-06T08:06:12.335-07:002017-09-06T08:06:12.335-07:00the product should be:
5 6
11 14the product should be:<br />5 6<br />11 14Anonymousnoreply@blogger.com