"Matrix multiplication in java using function" Code Answer's
You're definitely familiar with the best coding language Java that developers use to develop their projects and they get all their queries like "Matrix multiplication in java using function" answered properly. Developers are finding an appropriate answer about Matrix multiplication in java using function related to the Java coding language. By visiting this online portal developers get answers concerning Java codes question like Matrix multiplication in java using function. Enter your desired code related query in the search bar and get every piece of information about Java code related question on Matrix multiplication in java using function.
matrix multiplication in java
public class MatrixMultiplicationExample{
public static void main(String args[]){
//creating two matrices
int a[][]={{1,1,1},{2,2,2},{3,3,3}};
int b[][]={{1,1,1},{2,2,2},{3,3,3}};
//creating another matrix to store the multiplication of two matrices
int c[][]=new int[3][3]; //3 rows and 3 columns
//multiplying and printing multiplication of 2 matrices
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
c[i][j]=0;
for(int k=0;k<3;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}//end of k loop
System.out.print(c[i][j]+" "); //printing matrix element
}//end of j loop
System.out.println();//new line
}
}}
Matrix multiplication in java using function
// matrix multiplication java
public class MatrixMultiplicationJavaDemo
{
public static int[][] multiplyMatrix(int[][] matrix1, int[][] matrix2, int row, int column, int col)
{
int[][] multiply = new int[row][col];
for(int a = 0; a < row; a++)
{
for(int b = 0; b < col; b++)
{
for(int k = 0; k < column; k++)
{
multiply[a][b] += matrix1[a][k] * matrix2[k][b];
}
}
}
return multiply;
}
public static void printMatrix(int[][] multiply)
{
System.out.println("Multiplication of two matrices: ");
for(int[] row : multiply)
{
for(int column : row)
{
System.out.print(column + " ");
}
System.out.println();
}
}
public static void main(String[] args)
{
int row = 2, col = 3;
int column = 2;
int[][] matrixOne = {{1, 2, 3}, {4, 5, 6}};
int[][] matrixTwo = {{7, 8}, {9, 1}, {2, 3}};
int[][] product = multiplyMatrix(matrixOne, matrixTwo, row, col, column);
printMatrix(product);
}
}
Source: www.flowerbrackets.com
All those coders who are working on the Java based application and are stuck on Matrix multiplication in java using function can get a collection of related answers to their query. Programmers need to enter their query on Matrix multiplication in java using function related to Java code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about Matrix multiplication in java using function for the programmers working on Java code while coding their module. Coders are also allowed to rectify already present answers of Matrix multiplication in java using function while working on the Java language code. Developers can add up suggestions if they deem fit any other answer relating to "Matrix multiplication in java using function". Visit this developer's friendly online web community, CodeProZone, and get your queries like Matrix multiplication in java using function resolved professionally and stay updated to the latest Java updates.