code for multiplication of matrix in java using methods

code for multiplication of matrix in java using methods

code for multiplication of matrix in java using methods

View Answers

April 20, 2011 at 10:55 AM

   import java.util.*;
    class MatrixMultiplication{

        public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int[][] A = new int[3][3];
    int[][] B = new int[3][3];
    int[][] C = new int[3][3];
    System.out.println("Enter elements for matrix A : ");
    for (int i=0 ; i < A.length ; i++)
    for  (int j=0 ; j < A[i].length ; j++){
    A[i][j] = input.nextInt();
    }
    System.out.println("Enter elements for matrix B : ");
    for (int i=0 ; i < B.length ; i++)
    for  (int j=0 ; j < B[i].length ; j++){
    B[i][j] = input.nextInt();
    }
    System.out.println("Matrix A: ");
            for (int i=0 ; i < A.length ; i++){
                System.out.println();
                for  (int j=0 ; j < A[i].length ; j++){
                    System.out.print(A[i][j]+" ");
                      }
            }
    System.out.println();
    System.out.println();
    System.out.println("Matrix B: ");
            for (int i=0 ; i < B.length ; i++){    
                System.out.println();
                for  (int j=0 ; j < B[i].length ; j++){
                    System.out.print(B[i][j]+" ");
                      }
            }
    System.out.println();
    System.out.println();
    System.out.println("Result is: ");
    System.out.println();

    for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
    for(int k=0;k<3;k++){
    C[i][j]+=A[i][k]*B[k][j];
    }
    }
    }
    for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
    System.out.print(+C[i][j]+" ");
    }
    System.out.println();
    } 
    }
    }

October 28, 2011 at 10:12 PM

for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ for(int k=0;k<3;k++){ C[i][j]+=A[i][k]*B[k][j]; } } } It is a super formula for Multiplication of matrix

I also did this by using the following code

for(int i=1,c=1,d=1,p=1,o=1;o<=3;o++,++c,++p){ for(int j=1,q=1;j<=3;j++,++q){
z[p][q]=x[c][d]y[i][j]+x[c][d+1]y[i+1][j]+x[c][d+2]*y[i+2][j]; } }

the codeing which I done seems to be more complicated but I did with only two "for loops"









Related Tutorials/Questions & Answers:
code for multiplication of matrix in java using methods
code for multiplication of matrix in java using methods  code for multiplication of matrix in java using methods
Parallel multiplication matrix in java
Parallel multiplication matrix in java  hello dear I need parallel multiply matrix in java algorithm to account speed up and efficiency great wishes
Advertisements
Matrix Multiplication in Java
Matrix Multiplication in Java In this Java tutorial we will demonstrate you 'Matrix Multiplication in Java' with the help of a simple example from which you can easily learn how to write a matrix multiplication program in Java
Matrix multiplication
Matrix multiplication  program to read the elements of the given two matrices of order n*n and to perform the matrix multiplication
determinant of n*n matrix using java code
determinant of n*n matrix using java code  Here is my code... Scanner(System.in); System.out.println("enter dimension of matrix"); N...]; } System.out.println("enter the elements of matrix"); for(int i=0;i<N;i
parallel dense matrix multiplication
using dense parallel matrix multiplication. I request you to kindly provide me a code for Parallel Matrix multiplication on distributed systems using Java...parallel dense matrix multiplication  hi friends, i am a final year
Matrix Addition using RMI in Java
Matrix Addition using RMI in Java  Source Code for Matrix Addition using RMI in Java
Matrix multiplication in java
Matrix multiplication in java In this section we will learn about multiplication of two matrices. In java this is a simple program to multiply two matrices... two-dimensional array. Here we are going to develop a Java code for matrices
Find sum of all the elements of matrix using Java
Find sum of all the elements of matrix using Java A matrix is a rectangular array of numbers. The numbers in the matrix are called its entries or its elements. A matrix with m rows and n columns is called m-by-n matrix or m × n matrix
Multiplication of two polynomials using linked list in java
Multiplication of two polynomials using linked list in java  I am doing a program "Multiplication of two polynomials using linked list in java...; Node q = front; //insert in front if exponent is higher
Multiplication of two Matrix
Multiplication of Two Matrix   .... The Java two dimensional array  program is operate to the two matrix number. In this program also provided Java source code with understanding the Java
using class and methods - Java Beginners
using class and methods  Sir,Plz help me to write this below pgm. here is the question: Assume a table for annual examination results for 10... the following code: import java.util.*; public class Student{ int rollNo
Multiplication of two Matrix
for multiplying two matrix to each other. Here providing you Java source code... by using the array1.length. After getting both matrix then multiply to it. Both matrix will be multiplied to each other by using 'for' loop. So the output
Display tow dimensional array by matrix form using one for loop in java
Display tow dimensional array by matrix form using one for loop in java  Display tow dimensional array by matrix form using one for loop in java
code for a simple java program which performs basic arithmetic operation addition,subtraction,multiplication,division........
code for a simple java program which performs basic arithmetic operation addition,subtraction,multiplication,division........  code for a simple java...,multiplication,division
Java, matrix
"); System.out.println("3. Multiplication Of Matrix"); System.out.println("4. Exit...Java, matrix  java program to get output on the basis of users choice of switch statement perform operations addition, subtraction and multiplication
java code using swings
java code using swings  code that should be able to enter data of student details using all swings into the access database using jdbc connectivity
java program_big digits multiplication..
java program_big digits multiplication..  i want program about big digits multiplication program using java..plz tel me answer
Multiplication problem - Java Beginners
Multiplication problem  I am facing a peculiar problem in java regarding a multiplication. Please see below: 19300 * 0.001 = 19.3 19400 * 0.001 = 19.400000000000002 (why is this ??) 19500 * 0.001 = 19.5 Can anybody help
core java ,io operation,calling methods using switch cases
core java ,io operation,calling methods using switch cases  How to create a dictionary program,providing user inputs using io operations with switch cases and providing different options for searching,editing,storing meanings
multiplication
multiplication  multiplication of two number numbers entered by user minimum 100digits using GUI   Java Multiplication of two 100 digits number import java.awt.*; import java.math.*; import javax.swing.*; import
multiplication
multiplication  multiplication of two number numbers entered by user minimum 100digits using GUI   Java Multiplication of two 100 digits number import java.awt.*; import java.math.*; import javax.swing.*; import
An application using swings and vector methods
An application using swings and vector methods   Hi, I want an application in Java swings which uses good selection of Vectors methods
matrix calculator - Java Beginners
matrix calculator  hi..... can you help me in writing source code of matrix calculator in java... i know you are the best you can do it!!! show yourself
multiplication algorithms in java divide and conquer
multiplication algorithms in java divide and conquer  I need multiplication algorithms in java divide and conquer ask from user input two numbers in binary then the program multiply two number use multiplication algorithm in java
multiplication algorithms in java divide and conquer
multiplication algorithms in java divide and conquer  I need multiplication algorithms in java divide and conquer ask from user input two numbers in binary then the program multiply two number use multiplication algorithm in java
multiplication algorithms in java divide and conquer
multiplication algorithms in java divide and conquer  I need multiplication algorithms in java divide and conquer ask from user input two numbers in binary then the program multiply two number use multiplication algorithm in java
java string multiplication
java string multiplication  Is there any simple method of string multiplication in java ..?   public class StringMultiplication { public static void main(String[] args) { String number1 = "17"; String number2
java code using while loop
java code using while loop  
java code for PartialSearch using Map????
java code for PartialSearch using Map????  java code for Partial Search using Map
Java Matrix Multiplication Example
Java Matrix Multiplication Example In this tutorial, you will learn how... the multiplication of two matrices of any order. In the given program, firstly we have... and then accept the matrix elements as array elements. We have declared two
multiplication function in jsp using scriptlet function
multiplication function in jsp using scriptlet function   how to display data on text filed at total amount??? FlashTemplatesDesign.com Free Css Templates <!-- <form
Matrix - Java Beginners
Matrix  give me the Matrix program   Hi friend, Code for Matrix Example in Java class MatrixExample{ public static void main...(" ]"); } System.out.println(); } } For more information on java visit to : http
matrix determination in java
matrix determination in java  hai
Java Transpose of a matrix
Java Transpose of a matrix In this section, you will learn how to determine... to create a matrix. Then using the for loop statements, turn all the rows of the matrix into columns and vice-versa. Here is the code: import java.util.
Calling Methods Using SpEL
Calling Methods Using SpEL Spring 3 provides powerful Expression Language... by calling methods. Person.java: The Person class contains property named "... getPersonName() method to wire name property of the Person class using Spring
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
Reading RDF file using Java code in Eclipse
Reading RDF file using Java code in Eclipse  Could you please tel me what this statement means - Model model = ModelFactory.createDefaultModel
java code using combobox,radiobutton,checkbox
java code using combobox,radiobutton,checkbox  hi, send me java code for entering student details into ms access database, the code should includes combo box,radiobutton and checkboxes pl send as early as possible
View source code of a html page using java ..
View source code of a html page using java ..  I could find the html source code of a web page using the following program, http://download.oracle.com/javase/1.4.2/docs/api/java/net/URLConnection.html i could get the html code
Java methods
Java methods  What are the differences between == and .equals
how to use StringTokenizer to retrieve the class name, attributes name and methods name from the Java Source Code
and methods name from the Java Source Code  hi, I have done a program whereby it can read a Java file and then tokenize them into tokens. However, I am facing one problem which is retrieve the Class Name, Attributes Name and Methods Names
Error in MySQL Procedure Using JAVA Code
Error in MySQL Procedure Using JAVA Code  The following Java code (using Connector/J to create a stored procedure on MySQL 5.0) does not execute successfully. Identify the cause and available solutions. statement.execute
Create Multiplication Table from 1 to 10
Create Multiplication Table in Java In this section, you will learn how to create multiplication table from 1 to 10. For this purpose, we have created 2-dimensional Array 'array[][]' and using the for loop, we have stored the product
java plugin code for nutch using filter indexer
java plugin code for nutch using filter indexer  hello: i want... in the doc.add(name,value) . I don't know what is the error in it. Tthis is the code... = conf; } } I think that the error is in using parsedData but I don't know what I
input using scanner and add/sub/mul/div of a matrix
input using scanner and add/sub/mul/div of a matrix  hiiii...... performe matrix add/sub/mul/div using scanner
Writing code with multiple Class Methods and String Arrays
Writing code with multiple Class Methods and String Arrays  So what I am trying to do is create a code that lists music artists names using user... to generate the entire list once prompted. To give a better idea of how the code
Writing code with multiple Class Methods and String Arrays
Writing code with multiple Class Methods and String Arrays  So what I am trying to do is create a code that lists music artists names using user... to generate the entire list once prompted. To give a better idea of how the code
methods type - Java Beginners
methods type in Java  Give me an example programs of methods types in Java
to create a java class and methods
to create a java class and methods  How to create a java class without using the library class to represent linked lists of integers and also provide it with methods that can be used to reverse a list & append two lists.Also

Ads