Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer
Introduction to JAVA
before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
public class matrixsum
{
public static void main(String args[])throws Exception
{
DataInputStream din=new DataInputStream(System.in);
int twod[][]=new int[10][10];
int twod1[][]=new int[10][10];
int sum[][]=new int[10][10];
int i,j,r,c;
System.out.println("Enter the number of rows and column of the matrix");
r=Integer.parseInt(din.readLine());
c=Integer.parseInt(din.readLine());
System.out.println("Enter the number of first matrix");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
twod[i][j]=Integer.parseInt(din.readLine());
}
}
System.out.println("The first matrix are :");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
System.out.print(twod[i][j]+" ");
}
System.out.println();
}
System.out.println("Enter the number of second matrix");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
twod1[i][j]=Integer.parseInt(din.readLine());
}
}
System.out.println("The second matrix are :");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
System.out.print(twod1[i][j]+" ");
}
System.out.println();
}
System.out.println("The sum of the matrix are :");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
sum[i][j]=twod[i][j]+twod1[i][j];
System.out.print(sum[i][j]+" ");
}
System.out.println();
}
}
}
=========================================================================
Output :
Output :
No comments:
Post a Comment