Need help creating code for this assignment if you look at the picture and withi
ID: 3816034 • Letter: N
Question
Need help creating code for this assignment if you look at the picture and within the code will have tasks and will show what to do. The first picture is the assignment for this code, the second picture is just to help you understand this assignment
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
Hi, Please find my implementation.
Please let me know in case of any issue.
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 < 2; j++)
{
C[i][j] = 0;
for (int k=0; k < n; 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 <m; i++) {
for (int j=0; j <n; 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<n; i++) {
for (int j=0; j <p; 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<m; i++) {
for (int j=0; j <p; j++)
System.out.printf("%5d",C[i][j]);
System.out.println();
}
} // end main
} // end class
/*
Sample run:
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
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.