Program which reads two matrices and calculate their sum.

import java.io.*;
class test
{
public static void main(String[] asd)throws IOException
{
BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the values of Rows and Columns of Matrix.");
String num=obj.readLine();
int r=Integer.parseInt(num);
num=obj.readLine();
int c=Integer.parseInt(num);
int m1[][]= new int[r][c][/c];
System.out.println("Enter the values of the matrix not more then "+(r*c)+".");
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
{
num=obj.readLine();
m1[i][j]=Integer.parseInt(num);
}
int m2[][]= new int[r][c][/c];
System.out.println("Enter the values of the matrix not more then "+(r*c)+".");
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
{
num=obj.readLine();
m2[i][j]=Integer.parseInt(num);
}
int m3[][]=new int[r][c][/c];
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
m3[i][j]=m1[i][j]+m2[i][j];
System.out.println("Your Matrix is::");
for(int i=0;i<r;i++)
{    for(int j=0;j<c;j++)
{
System.out.print(m3[i][j]+"    ");
}
System.out.println();
}

}




}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s