Question

Line number 9 contains the code line that declares the result array ( asked in another question of this exam). On Line number

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Complete code:

package ok4;

public class multiply{
   public static void main(String[] args){
int frstMatrix[][]={{1, 9, 3},{0, -3, 14}};
int scndMatrix[][]={{0,7,10,-1},{24,3,4,1},{5,16,2,7}};
int result[][]=new int[frstMatrix.length][scndMatrix[0].length];

for(int col=0;col<scndMatrix[0].length;col++){
    for(int row=0;row<frstMatrix.length;row++){
        result[row][col]=0;
         for(int common=0;common<frstMatrix[0].length;common++){
           result[row][col] += frstMatrix[row][common]*scndMatrix[common][col];
         }
    }
}
System.out.println("Displaying the matrixes: ");
System.out.println("First Matrix:");
for(int i=0;i<frstMatrix.length;i++){
   for(int j=0;j<frstMatrix[0].length;j++)
     System.out.print(frstMatrix[i][j]+" ");
    System.out.println();
}
System.out.println("Second Matrix:");
for(int i=0;i<scndMatrix.length;i++){
   for(int j=0;j<scndMatrix[i].length;j++)
     System.out.print(scndMatrix[i][j]+" ");
    System.out.println();
}
    System.out.println("Result Matrix:");

for(int i=0;i<result.length;i++){
   for(int j=0;j<result[i].length;j++)
     System.out.print(result[i][j]+" ");
    System.out.println();
}

}
}

Explanation:

  • I have highlighted the missing code.
  • I have provided complete code to multiply two matrix and display each matrix.
  • Two matrix can be multiplied only if column count of first matrix is equal to row count of second matrix.
  • Output screen shot:
Add a comment
Know the answer?
Add Answer to:
Line number 9 contains the code line that declares the result array ( asked in another...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is for Java. Create ONE method/function that will return an array containing the row and...

    This is for Java. Create ONE method/function that will return an array containing the row and column of the largest integer i the 2D array. If the largest number is located on row 2, column 1, the method needs to return row 2 and column one. Do not use more than one method. Use the code below as the main. Please comment any changes. in java Given the main, create a method that RETURNS the largest number found in the...

  • whats the answers How many total integers elements are in an array with 4 rows and...

    whats the answers How many total integers elements are in an array with 4 rows and 7 columns? 07 28 11 What is the resulting array contents, assuming that itemList is an array of size 4 having contents -55, -1, 0, 9? for (i = 0; i < 4; ++i) { itemsList[i] - i; -54,0, 1, 10 O 0, 1, 2, 3 O 1, 2, 3, 4 O-55,-1, 0,9 Given an integer array myVals of size N_SIZE (i.e. int[] myVals...

  • Hi i need heeeeelllllp on this assignment i need to print the numbers diagonal top right...

    Hi i need heeeeelllllp on this assignment i need to print the numbers diagonal top right corner to the bottom left corner and i dont know how to do it please help me thank you dd another method to the bottom of the "TwoDimArraysMethods.java" file called "printDiagonalRL()"                                         public static void printDiagonalRL(int[][] matrix) 4. Call this method in the main file ("TwoDimArraysAsParam.java") passing it "board." e.g. TwoDimArraysMethods.printDiagonal(board); 5. Your new method should print any numbers along the diagonal from...

  • Three C Code Questions: 5. Write a C program that declares an array of 10 strings,...

    Three C Code Questions: 5. Write a C program that declares an array of 10 strings, each of max length 50 characters, and then reads an entire line of text from the keyboard into each string. 6. Write C code that finds the longest name in this array of strings that you read in Q5. Hint: find the position of the longest string, not the string itself. 7. Write a C program that creates a 4 x 6 two dimensional...

  • /** * A collection of methods related to multi-dimensional arrays. */ public class Array2Lab { /**...

    /** * A collection of methods related to multi-dimensional arrays. */ public class Array2Lab { /** * Return whether k is in list. * Precondition: the elements of list are not null. * @param list the array to be searched. * @param k the number to search for. * @return true if k is an element of list, and false otherwise. */ public static boolean contains(Object[][] list, Object k) { return false; }    /** * Create a String that...

  • Hi, can someone please help me implement the transpose, multiply(Matrix b), multiply(Matrix m, int threads), and...

    Hi, can someone please help me implement the transpose, multiply(Matrix b), multiply(Matrix m, int threads), and equals(Object in) methods? (This is Java) I really need help so please don't just refund the question. public class Matrix {1 public int[] [] matrix; 1 int[] [] trans; 1 public int x, y; 1 private boolean transposed; 1 1 public Matrix(int x, int y){1 matrix = new int[x][y1;1 this.x = x; this.y = y; 1 } 1 9 /*1 * This method takes...

  • 1.Write code for a Java method, printArray, that takes an int array as parameter and prints...

    1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...

  • Transfer C code of selection sort to MIPS code and print the sorted array/results data Array:...

    Transfer C code of selection sort to MIPS code and print the sorted array/results data Array: word 43, -5, 11, 12, 64, -7, 14, 71, 70, 13, -27 string: asciz"In" # Trantec the C code of selection sort to MIPS code. Do not modify the existing code and structure! text main la ŞtO, Array li $t1, 0 li $t7,11 mul $17, $17, 4 subi $t8,$t7, 4 # array length n-11 # 4*n #4*(n-1) # lis in $t1 and j is...

  • Transfer C code of selection sort to MIPS code and print the sorted array/results

    Transfer C code of selection sort to MIPS code and print the sorted array/results data Array: word 43, -5, 11, 12, 64, -7, 14, 71, 70, 13, -27 string: asciz"In" # Trantec the C code of selection sort to MIPS code. Do not modify the existing code and structure! text main la ŞtO, Array li $t1, 0 li $t7,11 mul $17, $17, 4 subi $t8,$t7, 4 # array length n-11 # 4*n #4*(n-1) # lis in $t1 and j is...

  • Using java fix the code I implemented so that it passes the JUnit Tests. MATRIX3 public...

    Using java fix the code I implemented so that it passes the JUnit Tests. MATRIX3 public class Matrix3 { private double[][] matrix; /** * Creates a 3x3 matrix from an 2D array * @param v array containing 3 components of the desired vector */ public Matrix3(double[][] array) { this.matrix = array; } /** * Clones an existing matrix * @param old an existing Matrix3 object */ public Matrix3(Matrix3 old) { matrix = new double[old.matrix.length][]; for(int i = 0; i <...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT