Home Tutorialhelp Comment this is what we want

 
 

Comment

sawsan
this is what we want,
April 22, 2010 at 3:48 PM

/**
* Multiply two matrices.
* Only defined for int: TODO: rewrite using 1.5 Generics to add
* support for long, float, and double.
* @author Ian F. Darwin, http://www.darwinsys.com/
* @version $Id: Matrix.java,v 1.4 2004/03/07 02:53:53 ian Exp $
*/
public class Matrix {

/* Matrix-multiply two arrays together.
* The arrays MUST be rectangular.
* @author Tom Christiansen & Nathan Torkington, Perl Cookbook version.
*/
public static int[][] multiply(int[][] m1, int[][] m2) {
int m1rows = m1.length;
int m1cols = m1[0].length;
int m2rows = m2.length;
int m2cols = m2[0].length;
if (m1cols != m2rows)
throw new IllegalArgumentException("matrices don't match: " + m1cols + " != " + m2rows);
int[][] result = new int[m1rows][m2cols];

// multiply
for (int i=0; i<m1rows; i++)
for (int j=0; j<m2cols; j++)
for (int k=0; k<m1cols; k++)
result[i][j] += m1[i][k] * m2[k][j];

return result;
}

/** Matrix print.
*/
public static void mprint(int[][] a) {
int rows = a.length;
int cols = a[0].length;
System.out.println("array["+rows+"]["+co… = {");
for (int i=0; i<rows; i++) {
System.out.print("{");
for (int j=0; j<cols; j++)
System.out.print(" " + a[i][j] + ",");
System.out.println("},");
}
System.out.println(":;");
}
public static void main(String[] argv) {
//+
int x[][] = {
{ 3, 2, 3 },
{ 5, 9, 8 },
};
int y[][] = {
{ 4, 7 },
{ 9, 3 },
{ 8, 1 },
};
int z[][] = Matrix.multiply(x, y);
Matrix.mprint(x);
Matrix.mprint(y);
Matrix.mprint(z);
//-
}
}
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Programming Tutorials

Two Dimensional Array Program
; program . In this session we will teach how to use of a two dimensional array... Two Dimensional Array Program Using Nested for loop... are going to make two dimensional array having three row and three columns.  

Java Beginners

Two- Dimensional Array - Java Beginners
Two- Dimensional Array  I am new in java programming. I am creating a two-dimensional array. This is my code ** class BinaryNumbers { public static void main(String[] args) { //create a two-dimensional array int ROWS = 21 

Core Java

Matrix multiplication in java
, we have to take two-dimensional array and the result should be saved in third two-dimensional array. Here we are going to develop a Java code for matrices...Matrix multiplication in java In this section we will learn about 

Core Java

Two dimensional array in java
Two dimensional array in java. In this section you will learn about two-dimensional array in java with an example. As we know that array is a collection... dimensional array is defined as an "array of array". In java the element 

Java Beginners

how do i begin a two dimensional array?
how do i begin a two dimensional array?  I'm new to java programming and need to create a two dimensional array that enters exactly what is entered in the first dimension and then the first non-white space character of what 

General

Two Dimensional Array Program
a integer for array declaration Two dimensional array program. We are going... Two Dimensional Array Program    ... will learn how to display arrange form of two dimensional array program 

Java Beginners

reverse two dimensional arrays in java
reverse two dimensional arrays in java  reverse array elements in two dimensional array such that the last element becomes the first 

General

Two Dimensional Array Program Using Nested For Loop
;. We are going to make a integer for array declaration Two dimensional array... Two Dimensional Array Program Using Nested For Loop ... of Java. In this lesson we will learn how to display arrange form of two 

General

Multiplication of two Matrix
. The Java two dimensional array  program is operate to the two matrix number... Multiplication of Two Matrix       This is a simple Java multidimensional array program 

Java Beginners

two dimensional - Java Beginners
two dimensional  write a program to create a 3*3 array and print the sum of all the numbers stored in it.  Hi Friend, Try the following code: import java.io.*; import java.util.*; public class matrix 

General

Square Elements of Two Dimensional Array
the two dimensional array program and its square. This session provide you... Square Elements of Two Dimensional Array   ...: We are going to display the square of two matrix. Firstly, we have to define 

Java Tips and Examples

Two-dimensional arrays
in each of those arrays. To process a two-dimensional array, we use nested...; Two-dimensional arrays are defined as "an array of arrays". Since an array type is a first-class Java type, we can have an array of ints 

Java Interview Questions

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 

Java Interview Questions

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 

General

Dividing Element of Two Dimensional Array
Java program.  The java two dimensional array program is operate the two... Dividing  Element of Two Dimensional Array... divide of two matrix. First all to we have to define class " 

Java Tips and Examples

Multiplication of two Matrix
program that will multiply two matrix. Two dimensional array represents... Multiplication of two Matrix    ... for multiplying two matrix to each other. Here providing you Java source code 

Java Tips and Examples

Multi-dimensional arrays
. It does, however, supports an array of arrays. In Java, a two-dimensional array...; So far we have studied about the one-dimensional and two... that supports it, the element of the two-dimensional array x is denoted by x[i,j].  

Java-Tutorials

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... will write a simple program, which will multiply two matrix. A Two dimensional array 

General

Declare string array in Java (one and two dimensional)
Declare string array in Java (one and two dimensional... program also teaches you how to declare two dimensional array in Java... dimensional array and two dimensional as well. 1. String arr[] = new String 

PHP Questions

php two dimensional array
php two dimensional array  php two dimensional array example 

Java Beginners

two dimensional array
two dimensional array  how tow dimensional array works.How those loopes get incremented .and how every time the value of k changes 

General

Three Dimensional Array program
Three Dimensional Array program       This is a very simple Java program. In this program we will learn how to use three dimensional array. Firstly, we have to define class 

Java-Tutorials

Array in Java
. Different types of array used in Java are One-dimensional, Two-dimensional and multi...[] = {50,60,70,80,90}; Two-dimensional arrays: Two-dimensional arrays are "an array of arrays". We can have an array of ints, an array of Strings 

Java Beginners

one dimensional array using java
one dimensional array using java  design and implement a java program that will read a file containing numbers and compute the following statistics: the range(low,high) the average and the median 

Java Beginners

Two Dimensional array program
Two Dimensional array program  consider a two dimensional array... to elements of the array such that the last element become the first one and the first become the last.let the program output elements of the first array 

Java3D Questions

one dimensional array program
one dimensional array program  Design and implement a java program that will read a file containing numbers and compute the following statistics: the rannge( low, high), the average and the median(middle number). Notes 

General

Multiplication of Two Number in Class
Multiplication of Two Number in Class       This section we will learn how to use...; Description this program  In this program we are going to use two any number 

JSP Tutorials

Multidimensional Array Java
to store it in an array. We use mostly two types of arrays that is simple array and multi dimensional array.   In the example given below we have used two dimensional array. A two dimensional array can be thought as a grid 

Java Beginners

A single dimensional array is called
A single dimensional array is called  What is a single dimensional array called?   A single dimensional array is called LIST 

General

Creation Time Comparison of Multi Dimensional Array- Java Tutorials
Creation Time Comparison of Multi Dimensional Array In this section, we will compare the creation time between the different size/dimension of array.  As you know that multidimensional array is the array of arrays. Practically 

Java Beginners

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...() { numC = 0; numE = 0; next = null; } // constructor with two argument public 

Java Interview Questions

Display tow dimensional array using one for loop in java
Display tow dimensional array using one for loop in java  Display tow dimensional array using one for loop in java 

General

Changing the value of Array in Java
dimensional array program. In  this program firstly we are going to define... Changing the Value of Array in Java       This is very simple of one dimensional array program 

Java Code Examples

Java Matrix Multiplication Example
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... the multiplication of two matrices, we have performed following distinctive steps 

General

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 Interview Questions

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 Beginners

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 Beginners

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 Interview Questions

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 

Java Beginners

java program_big digits multiplication..
java program_big digits multiplication..  i want program about big digits multiplication program using java..plz tel me answer 

General

Dividing of two Matrix in Java
;Here you will learn how to use two matrix array for developing Java program.  The java two dimensional array program is operate the two matrix. Now we... Dividing of two Matrix in Java    

General

The Array Palindrome Number in Java
The Array Palindrome Number in Java   .... In this section you will read how to uses palindrome one dimensional array... provide you the best explanation with the Java source code. Here we are going 

Java Tips and Examples

Java Array declaration
Java Array declaration In this section you will learn how to declare array in java. As we know an array is collection of single type or similar data type... in the memory with array size 5 which hold five element. To declare two-dimensional 

Development process Questions

Conversion - Development process
Conversion  Why is there a need to convert from Java to .NET? What is the theory of conversion from java to .NET? How it is done?   Hi friend, Two paths are available for migrating Java applications to .Net 

General

JavaScript array merge
;  In this Tutorial we want to describe you a code that help you in understanding how to merge two different array into one array using Java Script. We... print the list of element in an array. In the same way we declare another array 

Java Beginners

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 

Java Interview Questions

java array
java array Two cells is a matrix will be called connected if they are adjacent on either x-axis or y-axis  Two cells is a matrix will be called... takes 2 dimensional integer array as input and prints out heaviest island 

Java Beginners

array - Java Beginners
array  Accept a two dimensional array from the user check if this array is symetric display a message yes,if it is symetric otherwise display it ,is not symetric 

Java Beginners

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 

JSP Servlet Questions

how to store array values into two different tables in java?
how to store array values into two different tables in java?  I have use 4/5 textboxes with same name(e.g.text1) and I get the values in a array and now I want to store these values in two different tables(i.e store 2 array 

Java Beginners

Type Conversion - Java Beginners
Type Conversion   Hai, rajanikanth, Please explain how to convert from integer value to a string value .In a database operation i want to convert... for conversion 

General

Java Date Conversion
Java Date Conversion In java date conversion, two packages are used... Java Converts String into Date In this example we are going to convert...; Java Converts String into Calendar In this example we 

Java Beginners

two dimansional array - Java Beginners
two dimansional array  Modify the following program so that it computes and prints the tables of powers from 1 to 15.( 1 to 15 to the power 1, Squared, and Cubed: like below) it should look like 1 1 1 2 4 8 3 9 27 and so 

Java Beginners

Java array in currency converter
Java array in currency converter  Hi all, My sister is trying to teach me java. She's in school for programming and I'm not but I am just trying... conversion beyond your array size. After the user selects quit from the menu 

Java Beginners

How to Create Multiplication Table from 1 to 10?
How to Create Multiplication Table from 1 to 10?  Hi, I want to develop an small application store products. So, i how to create multiplication... table. Thanks   Hi, Did you want to create multiplication table 1 

Java Beginners

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 

General

How to declare String array in Java?
elements of one dimensional array and two dimensional array. 1. String arr... and initialize two dimensional array String dim2...Following example will show you how to declare string array in java 

Java-Tutorials

Array declaration in Java
an array in Java: One dimensional array can be declared as: int OneDArray[]; or int...Array in Java can be used to store similar kind of data or element... an array, we must know it's index value. We can give any name 

Java Interview Questions

Array
Array  can we create an array of size 1 lakh in java programming 

PHP Questions

Byte array to PDF Conversion
Byte array to PDF Conversion  Hi, Am getting a letter Format in Byte array and i have to display that in PDF.Is that possible in PHP ? If so... dont want that now. It is not neccessary that i need PDF.Any Uneditable format 

Java Beginners

Java Array - Java Beginners
Java Array  Q4-Write a program to exchange the nondiognal elements of a two dimensional array A of size NxN without using any other array ie. each a[i][j]with a[j][i] where i is not equal j?   Hi Friend, Please try 

Java Tips and Examples

Java - Array in Java
Array Example - Array in Java     ... of arrays are used in any programming language such as: one - dimensional, two - dimensional or can say multi - dimensional.  Declaration of an array:   

Java Beginners

java conversion
java conversion  how do i convert String date="Aug 31, 2012 19:23:17.907339000 IST" to long value 

Java Beginners

Need coding help - two dimensional matrix and it returns back a boolean.
Need coding help - two dimensional matrix and it returns back a boolean.  I need to write a code method that accepts a two dimensional integer arrays as the argument and returns true if the array or matrix is left or right 

Java Beginners

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 

Java-Tutorials

Java Multi Dimensions Array - Java Tutorials
declare a two dimensional array as : int twoD[][]=new int [4][5]; You can also... multidimensional. For accessing elements of array we use its index. In other words, we can say... DevArray 1.9 2.9 3.4 3.5 Multidimensional array : In java 

Java Beginners

Java array - Java Beginners
a program tofind sum of all non dioganal elements of a two dimensional NxN array? Q4-Write a program to exchange the nondiognal elements of a two dimensional...Java array  Q 1- write a program that counts the frequency 

Programming Tutorials

Compare two char array in java
Description: This tutorial demonstrate how to compare two character array are equal or not. The Arrays.equals(c1, c2) helps to compare it and return boolean value. Code: import java.util.Arrays 

Java Beginners

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 

Java Beginners

String to Date Conversion - Java Beginners
)); For read more information : http://www.roseindia.net/java/java-conversion.... But I dont want the date/time field of access database to be changed to text...  Hi friend, For conversion in this format : 11/SEP/2008 07:07:32 

Java Tips and Examples

Sum of two Matrix
to this. In this program we are going to calculate the sum of two matrix. To make this program, we need to declare two dimensional array of type integer. Firstly...; In this section, we are going to calculate the sum of two matrix 

JSP Servlet Questions

java array problem
java array problem  suppose i have an array a[] at a[0] i have value 5,7 the thing is that i want to assign the value of array a[0]=5,7 to two variable let it be j,k that is j=5 and k=7 plz help regards 

C Tutorials

C Array of String
and handled like a 2d(two dimensional) arrays. You can see in the given example that we have declare a 2 dimensional character array consisting of three 'rows' and twelve... C Array of String       

Java Beginners

PDF to Word Conversion - Java Beginners
PDF to Word Conversion  Hello, Can we convert a PDF document to Microsoft word document thru Java. If its not possible in Java, is it possible in any other language 

Java Beginners

need help with two dimensional array that takes input from user and bubble sorts and selections sorts
need help with two dimensional array that takes input from user and bubble... cannot figure out how i can declare a two dimensional array without knowing how... many words he/she types without using an array list.   Thank you. I 

Java Beginners

Java array
Java array  Java program to find first two maximum numbers in an array,using single loop without sorting array 

Java Interview Questions

Array list java code - Java Interview Questions
Array list java code  Create an employee class with an employee id's... an employee id is given, display his name & address? Please provide the DETAIL java code for this query..thanks in advance...   Hi Friend, What do you want 

Java Beginners

To find first two maximum numbers in an array
To find first two maximum numbers in an array  Java program to find first two maximum numbers in an array,using single loop without sorting array 

JSP Interview Questions

I want this jsp answers
I want this jsp answers    How can we declare third party classes... jsp page, server can develop a .java file for a particular jsp page or not? What... for particular jsp pages? If we want to develop any jsp pages using eclipse where we can 

JSP Interview Questions

I want this jsp answers
I want this jsp answers    How can we declare third party classes... jsp page, server can develop a .java file for a particular jsp page or not? What... for particular jsp pages? If we want to develop any jsp pages using eclipse where we can 

General

JavaScript Array
.   JavaScript array merge In this tutorial we want... In this tutorial we want to describe you a code that help you in understanding Java....   JavaScript array method In this tutorial we want 

Vehicle Tracking Technology

What is Trilateration?
trilaterlation. Trilateration can be either two dimensional or three dimensional. Let... What is Trilateration?       Introduction GPS receivers calculate the position of objects in two 

Java Beginners

want a code
want a code  I am trying to write Java code for creating a file of any type (either text,csv,or any other format). What I need is : The file generated should be zipped and password-protected. When I try to open the file, it asks 

Java Beginners

Difference in two dates - Java Beginners
on that. The thing is, that I need to find the difference between the two dates in JAVA, and so far I don't know how to do that ..... What I had done so far is as follows...Difference in two dates  Hello there once again........ Dear Sir 

Java Beginners

mahesh want to know java with good understanding
mahesh want to know java with good understanding  I need to know about java beans(what are java beans,why we use java beans, etc...).I want an example program and it's output also.please teach me...   Java Beans 

Java Beginners

pdf to xml conversion
pdf to xml conversion  i want to convert pdf file into xml file.. where i am having a table in pdf file with some headers and some data into it. i want the headers to be the tag of xml file. how can i do that using java? please 

Java Interview Questions

ARRAY SUB - Java Interview Questions
ARRAY SUB  What Is A Sub Array ?I Want defination ?How To Declare Sub Array 

General

Display Different Elements from two ArrayLists in Java
Display Different Elements from two ArrayLists Java In this section, we are going to compare two array lists and display the different elements from both of them. To show the different elements from the two list, we have created two 

Java Beginners

object conversion - Java Beginners
/java-conversion/ObjectToDouble.shtml Thanks... sandeep kumar suman...object conversion   Hi, Can anybody tell me the object conversion in java.   Hi sandeep Can u please tell me in details about your 

Applet Questions

conversion Applet
conversion Applet  I am a java beginner.................. strong texthow to create JApplet that prompts the user to enter a distance in miles in a JTextField and then converts mile to kilometers and display the result as XX.XX 

General

Java Conversion
Java Conversion      ... to ByteArray Here we will learn the conversion of an input stream into a byte... illustrate the conversion from char to Byte. Here, we are going to convert a char type 

Java Beginners

intersection of two java arrays
intersection of two java arrays  I am trying to figure out how to compare two arrays and get the intersection and put this into a third array of the correct size. I know how to copy the two arrays into the third array but am 

Java Beginners

java array
java array  q4.array Write a program that accepts two arrays, an array of fruit names and an array of price of fruits, and a fruit name and returns the price of the fruit. (Assume that a price in the second array corresponds 

General

JavaScript Array of checkboxes
JavaScript Array of checkboxes       In this Tutorial we want to describe you a code that help you in understanding JavaScript Array of checkboxes. For this we 

Java Beginners

Java Conversion Question - Java Beginners
Java Conversion Question   Hello sir ,How i can Convert Java Code to Vb.net ,Plz Help Me 

General

JavaScript Array of number
;  In this Tutorial we want to describe you a code that help you in understanding Java Script array number of elements. We are using JavaScript as script language. We declare an array variable that is used to store array object 

General

JavaScript array of functions
JavaScript array of functions       In this Tutorial we want to describe you a code that help in understanding a JavaScript array of functions. For this we are using Java Script 

Java Beginners

compare two strings in java
compare two strings in java  How to compare two strings in java...) { System.out.println("The two strings are the same."); } } } Output: The two strings are the same. Description:-Here is an example of comparing two 

General

Array Empty
Array Empty       In this Tutorial we want to describe you a code that makes you easy to understand in an Array Empty. For this example we are using Java Scripting 

Java Tips and Examples

Java Array Declaration
Java Array Declaration       As we declare a variable in Java, An Array variable is declared... in an  array. To represent the variable as an Array, we use [] notation. These two 

Advertisements Advertisements
 

 

 

DMCA.com