About 880,000 results
Open links in new tab
  1. java - How to multiply 2 dimensional arrays? Matrix Multiplication ...

    Feb 4, 2014 · int firstarray[][] = {{1, 2, -2, 0}, {-3, 4, 7, 2}, {6, 0, 3, 1}}; int secondarray[][] = {{-1, 3}, {0, 9}, {1, -11}, {4, -5}}; /* Create another 2d array to store the result using the original arrays' lengths on row and column respectively. */ int [][] result = new int[firstarray.length][secondarray[0].length]; /* Loop through each and get ...

  2. Java Program to Multiply Two Matrix Using Multi-dimensional Arrays

    In this program, you'll learn to multiply two matrices using multi-dimensional arrays in Java.

  3. Multiplying 2d array in java - Stack Overflow

    Feb 9, 2013 · I have declared an array that i would like to multiply the value of the first column by value of the second column of each row and create a grand sum of these products. I have tried the code listing below, what am i missing. public static void(String[] args) { int array_x[][]={{9,8},{2,17},{49,4},{13,119},{2,19},{11,47},{3,73}}; int sum = 0;

  4. Multiplying 2D arrays in Java - Stack Overflow

    Apr 4, 2022 · Multiplying two 2D array work on the following algebraic expression to find out the resultant array: result[i][j]= a[i][k] * b[k][j] Hint: In this case, inside the method, declare a 2D int[][] array reference variable and instantiate it with a size of a.length x b[0].length .

  5. Java Program to Multiply Two Matrices - Tpoint Tech

    Dec 7, 2024 · We can perform matrix multiplication in Java using a simple nested for loop approach to advance approach. The nested for loop approach has a time complexity of O (n3). The time complexity of matrix multiplication can be improved using Strassen algorithm which has O (nlog7). How to Perform Matrix Multiplications?

  6. Java Program to multiply two matrices - GeeksforGeeks

    Dec 26, 2021 · Given two matrices, the task to multiply them. Matrices can either be square or rectangular. Examples: {3, 4}} mat2[][] = {{1, 1}, . {1, 1}} Output : {{3, 3}, . {7, 7}} Input : mat1[][] = {{2, 4}, . {3, 4}} mat2[][] = {{1, 2}, . {1, 3}} . Output : {{6, 16}, . {7, 18}}

  7. Java program to Multiply two Matrices - Tutorial Gateway

    Write a Java program to multiply two Matrices with an example, or write a program to perform the multiplication of two multidimensional arrays. To perform the matrix multiplication, the number of columns in the first matrix must equal the total number of rows in the second matrix.

  8. Java Program to Perform Matrix Multiplication - Java Guides

    In this tutorial, we will write a Java program to perform matrix multiplication. 2. Program Steps. 1. Define a class named MatrixMultiplication. 2. Inside the main method, define two 2D arrays matrix1 and matrix2 representing the matrices to be multiplied. 3. Check if the number of columns in matrix1 is equal to the number of rows in matrix2 ...

  9. How Can I Multiply Two Arrays Like int [] * int [] in Java?

    Apr 5, 2022 · Just create target array of sufficient length, loop over the indices of the input arrays, multiply the elements at the source indices and assign them to the corresponding target index. So what the stream is doing is essentially this: for(int i = 0; i < a.length; i++) { c[i] = a[i] * b[i]; }.

  10. Java Program to Multiply Two Matrices - Matrix Multiplication

    Sep 27, 2023 · How to write a Java program to multiply two matrices in Java is a very good programming exercise to get familiar with the two-dimensional array in Java. this example teaches about how to multiply arrays, how to access elements from a multi-dimensional array, how to pass them to a function etc.

Refresh