Java program on matrix addition




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();
}
}
}


Related Articles

Creating new JEE 5 applications (Java and EJB Web Services) using RAD 7.5

Now days, most of the enterprise applications are developed in RAD 7.0+ (Rational Application Developer). The Web service application can be written in Java or in EJB. For creating Web services in Java or EJB, the vast documentation is available. Referring such documentation during speedy development period becomes a hectic job. So to avoid it, this article will help to easily develop a JEE5 application using simple steps.

Program for Addition performer in Java

This article provides a description to the addition performer in Java, that can perform addition operation on two input numbers. Code for the addition performer is provided in the article. The program is based on use of Swings. In Java Frames can be created and different text fields alongwith labels corresponding to them can be added. And use of all these elements can develope an efficient adder.

What is difference between an Interface and Abstract class in Java?

Are you looking for an article which explains the concepts of an Interface and Abstract class in simple language? Then your search ends here. Read this article, herein the detail about abstract class and an Interface is given. Also the important differences between an Interface and Abstract class is in Java is explained. This article highlights the important aspects regarding whether abstract class to be used or an Interface is to be used for given requirement of Enterprise application.

Directory Structure - XML Output

In this article, I have submitted a Java program. We will be able to get the dynamic XML file with treeview represents a folder and file structure of a given folder path using it. This Java program also show how to use a recursive function to read a directory structure and then save it to XML file. I commented properly for your better understanding how the program flow goes. The output XML file is well-formed

More articles: Java

Comments

No responses found. Be the first to 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:
    Email: