Sunday , 29 November 2015
Home » Array Related Programs » [Question 10] ISC 2013 (Theory) Paper Solved

[Question 10] ISC 2013 (Theory) Paper Solved


A class Matrix contains a two dimensional integer array of order [m x n]. The maximum value possible for both ‘m’ and ‘n’ is 25. Design a class Matrix to find the difference of the matrices. The details of the members of the class are given below:

Class name : Matrix

Data members/instance variables:
arr[ ][ ] : stores the matrix element
m : integer to store the number of rows
n : integer to store the number of columns

Member functions:
Matrix(int mm, int nn) : to initialize the size of the matrix m = mm and n = nn
void fillarray() : to enter the elements of the matrix
Matrix SubMat(Matrix A) : subtract the current object from the matrix of parameterized object and return the resulting object
void display() : display the matrix elements

Specify the class Matrix giving details of the constructor(int,int), void fillarray(), Matrix SubMat(Matrix A) and void display(). Define the main() function to create objects and call the function accordingly to enable the task.

Programming Code:

* The class Matrix inputs 2 Matrices as objects and subtracts the first from the second matrix
* @author :
* @Program Type : BlueJ Program - Java
* @Question Year : ISC Theory 2013 Question 10

class Matrix
static BufferedReader br=new BufferedReader (new InputStreamReader(;
int arr[][];
int m,n;
Matrix(int mm, int nn) //parameterised constructor
    arr=new int[m][n];

void fillarray()throws IOException //function for inputting the values in the Matrix
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
        System.out.print("Enter Element at ["+i+"]["+j+"] : ");

Matrix SubMat(Matrix A) //function for subtractng the calling Object (Matrix) from the Matrix A
Matrix C=new Matrix(m,n); //Object for storing the result
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
        /* keyword 'this' is referring to the object which will call the function SubMat(Matrix) */
return C;

void display() //function for displaying the Matrix
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)

public static void main(String args[])throws IOException
    System.out.print("Enter the number of Rows: "); //Inputting Number of Rows
    int r=Integer.parseInt(br.readLine());
    System.out.print("Enter the number of Columns: "); //Inputting Number of Columns
    int c=Integer.parseInt(br.readLine());
    if(r>25 || c>25)
    System.out.println("Out of Range");
        Matrix X=new Matrix(r,c); //The 1st Matrix
        Matrix Y=new Matrix(r,c); //The 2nd Matrix
        Matrix Z=new Matrix(r,c); //The Resultant Matrix

        //Inputting 1st Matrix by calling the function fillarray()
        System.out.println("\nEnter the 1st Matrix"); 

        //Inputting 2nd Matrix by calling the function fillarray()
        System.out.println("\nEnter the 2nd Matrix");

        //Displaying 1st Matrix by calling the function display()
        System.out.println("\nThe 1st Matrix");

        //Displaying 2nd Matrix by calling the function display()
        System.out.println("\nThe 2nd Matrix");

        /*Calling the function SubMat() using the object 'X' in order to subtract the values of
          Matrix X from Matrix Y*/

        //Displaying the resultant Matrix by calling the function display()
        System.out.println("\nThe Resultant Matrix"); 


Enter the number of Rows: 2
Enter the number of Columns: 3

Enter the 1st Matrix
Enter Element at [0][0] : 15
Enter Element at [0][1] : 2
Enter Element at [0][2] : 4
Enter Element at [1][0] : 53
Enter Element at [1][1] : 19
Enter Element at [1][2] : 37

Enter the 2nd Matrix
Enter Element at [0][0] : 11
Enter Element at [0][1] : 50
Enter Element at [0][2] : 3
Enter Element at [1][0] : 9
Enter Element at [1][1] : 45
Enter Element at [1][2] : 8

The 1st Matrix
15 2 4
53 19 37

The 2nd Matrix
11 50 3
9 45 8

The Resultant Matrix
-4 48 -1
-44 26 -29

Check Also

default thumbnail

Collection of Number based Programs using Recursion [ISC Computer Science]

This PDF is a collection of various number based programs done using the Recursive concept. The unique feature of this collection is that along with the recursive codes, we have provided the Iterative codes of the same program as well. This will facilitate the students in understanding the concept of recursion well.

Leave a Reply

Your email address will not be published. Required fields are marked *