Resources » Articles/Knowledge Sharing » Computer & Technology

Java program on matrix addition


Posted Date: 20-Jul-2010  Last Updated:   Category: Computer & Technology    
Author: Member Level: Gold    Points: 2






class AddMatrix
{
public static void main(String[] args)
{
int aiFirstArray[][]= {{1,2,3},{4,5,6}};
int aiSecondArray[][]= {{7,8,9},{10,11,12}};
int row1=ai.FirstArray.length;
int col1=ai.FirstArray[1].length;

System.out.println("The first matrix: ");
System.out.println();
for(int row= 0;row {
for(int col= 0;col<=col1;col++)
{
System.out.print(" "+ aiFirstArray[row][col]);
}
System.out.println();
}
int row2=ai.SecondArray.length;
int col2=ai.SecondArray[1].length;

System.out.println("The Second matrix: ");
System.out.println();
for(int row=0;row {
for(int col=0;col<=col2;col++)
{
System.out.print(" "+ aiSecondArray[row][col]);
}
System.out.println();
}
System.out.println("Addition of the above matrices: ");
for(int row = 0; row < row1; row++) {
for(int col = 0; col <= col1; col++) {
System.out.print(" "+(aiFirstArray[row][col]+aiSecondArray[row][col]));
}
System.out.println();
}
}
}


Did you like this resource? Share it with your friends and show your love!




Responses to "Java program on matrix addition"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Awards & Gifts
    Active Members
    TodayLast 7 Daysmore...

    Online Members

    Subhadra
    More...
    ISC Technologies, Kochi - India. Copyright © All Rights Reserved.