Need help completing assignment!! Attached instructions public class MoreProduct
ID: 3602209 • Letter: N
Question
Need help completing assignment!! Attached instructions
public class MoreProducts
{
public static void main(String[] args)
{
// create the array A exactly as shown:
// 19 18 22 23
// 16 25 2 67
// 26 3 80 99
// 80 80 80 80
// 66 82 13 26
int[][] A = {};
// create the array B exactly as shown:
// 89 10
// 22 32
// 7 59
// 44 1
int[][] B = {};
// prepare the product array C, currently empty (filled with 0's)
int[][] C = new int[A.length][B[0].length];
int m = ____________; // number of rows in Matrix A
int n = ____________; // number of columns in Matrix A, which must equal number of rows in Matrix B
int p = ____________; // number of columns in Matrix B
// compute the dot product of A and B, store the results in C
for (int i=____; i < ____; i++)
{
for (int j=____; j < ____; j++)
{
C[i][j] = 0;
for (int k=____; k < ____; k++)
// sum the values for C
C[i][j] += A[____][____]*B[____][____];
}
}
// print A
System.out.println("Matrix A ");
for (int i=____; i <____; ____) {
for (int j=____; j < ____; ____)
System.out.printf("%5d",A[____][____]);
System.out.println();
}
System.out.println();
// print B
System.out.println("Matrix B ");
for (int i=____; i< ____; ____) {
for (int j=____; j <____; ____)
System.out.printf("%5d",B[____][____]);
System.out.println();
}
System.out.println();
// print C
System.out.println("Matrix C ");
for (int i=____; i< ____; ____) {
for (int j=____; j < ____; ____)
System.out.printf("%5d",C[____][____j]);
System.out.println();
}
} // end main
} // end class
Explanation / Answer
MoreProducts.java
public class MoreProducts
{
public static void main(String[] args)
{
// create the array A exactly as shown:
// 19 18 22 23
// 16 25 2 67
// 26 3 80 99
// 80 80 80 80
// 66 82 13 26
int[][] A = {{19,18,22,23},{16,25,2,67},{26,3,80,99},{80,80,80,80},{66,82,13,26}};
// create the array B exactly as shown:
// 89 10
// 22 32
// 7 59
// 44 1
int[][] B = {{89,10},{22,32},{7,59},{44,1}};
// prepare the product array C, currently empty (filled with 0's)
int[][] C = new int[A.length][B[0].length];
int m = 5; // number of rows in Matrix A
int n = 4; // number of columns in Matrix A, which must equal number of rows in Matrix B
int p = 2; // number of columns in Matrix B
// compute the dot product of A and B, store the results in C
for (int i=0; i <m; i++)
{
for (int j=0; j <p; j++)
{
C[i][j] = 0;
for (int k=0; k <4; k++)
// sum the values for C
C[i][j] += A[i][k]*B[k][j];
}
}
// print A
System.out.println("Matrix A ");
for (int i=0; i <5;i++) {
for (int j=0; j <4; j++)
System.out.printf("%5d",A[i][j]);
System.out.println();
}
System.out.println();
// print B
System.out.println("Matrix B ");
for (int i=0; i< 4; i++) {
for (int j=0; j <2; j++)
System.out.printf("%5d",B[i][j]);
System.out.println();
}
System.out.println();
// print C
System.out.println("Matrix C ");
for (int i=0; i< 5; i++) {
for (int j=0; j < 2; j++)
System.out.printf("%5d",C[i][j]);
System.out.println();
}
} // end main
} // end class
_________________
Output:
Matrix A
19 18 22 23
16 25 2 67
26 3 80 99
80 80 80 80
66 82 13 26
Matrix B
89 10
22 32
7 59
44 1
Matrix C
3253 2087
4936 1145
7296 5175
12960 8160
8913 4077
________________Thank YOu
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.