Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML

Search:
   Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML Facing Programming Problem? Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
Sum of two Matrix
In this section, we are going to calculate the sum of two matrix and containing its rows and columns.
 
 

Sum of  two Matrix

                         

In this section, we are going to calculate the sum of two matrix and containing its rows and columns. See below for better understanding 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 it calculates the length of the both the arrays. Now we need to make a matrix out of it. To make the matrix we will use the for loop. By making use of the for loop the rows and column will get divide. This process will be performed again for creating the second matrix.

After getting both the matrix with us, we need to sum both the matrix. The both matrix will be added by using the for loop with array[i][j]+array1[i][j]. The output will be displayed by using the println() method.

Here is the code of this program:

class MatrixSum{
    public static void main(String[] args)  {
      int array[][]{{4,5,6},{6,8,9}};
    int array1[][]{{5,4,6},{5,6,7}};
    System.out.println("Number of Row= " + array.length);
    System.out.println("Number of Column= " + array[1].length);
    int l= array.length;
    System.out.println("Matrix 1 : ");
      for(int i = 0; i < l; i++) {
      for(int j = 0; j <= l; j++) {
        System.out.print(" "+ array[i][j]);
      }  
    System.out.println();
        }  
    int m= array1.length;
    System.out.println("Matrix 2 : ");
      for(int i = 0; i < m; i++) {
      for(int j = 0; j <= m; j++) {
        System.out.print(" "+array1[i][j]);
      }  
    System.out.println();
        }
    System.out.println("Addition of both matrix : ");
      for(int i = 0; i < m; i++) {
      for(int j = 0; j <= m; j++) {
        System.out.print(" "+(array[i][j]+array1[i][j]));
      }  
    System.out.println();
        }
    }
}

Output of program:

C:\amar work>javac MatrixSum.java

C:\amar work>java MatrixSum
Number of Row= 2
Number of Column= 3
Matrix 1 :
4 5 6
6 8 9
Matrix 2 :
5 4 6
5 6 7
Addition of both matrix :
9    9   12
11 14  16

Download this Example

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

this is the site which we can found nice stuffs
without assitance of teaching u can get everything by ur own..hats off for this site proprietor...

Posted by rajesh on Friday, 02.1.08 @ 19:30pm | #46875

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.