A Strong MatRev program ISC 2019 Object passing
Design a class MatRev to reverse each element of a matrix. Example:
Watch the video to learn more about java
https://www.youtube.com/watch?v=QZKcULOC4lg
This question was asked in the ISC 2019. It is a Object passing type of program. Here an object of the same class is passed as an argument in the function of the class
Design a class MatRev to reverse each element of a matrix.
Example:

Some of the members of the class are given below:
Class name: MatRev
Data members/instance variables:
arr[][] : to store integer elements
m: to store the number of rows
n: to store the number of columns
Member functions/methods:
MatRev(int mm, int nn): parameterized constructor to initialise the data members m = mm and n = nn
void fillarray(): to enter elements in the array
int reverse(int x): returns the reverse of the number x
void revMat(MatRev P): reverses each element of the array of the parameterized object and stores it in the array of the current object
void show(): displays the array elements in matrix form
Define the class MatRev giving details of the constructor ( ), void fillarray (), int reverse(int), void revMat(MatRev) and void show(). Define the main () function to create objects and call the functions accordingly to enable the task.
import java.util.Scanner;
class MatRev
{
int arr[][];
int m;
int n;
public MatRev(int mm, int nn)
{
m = mm;
n = nn;
arr = new int[m][n];
}
public void fillArray()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter matrix elements:");
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
arr[i][j] = sc.nextInt();
}
}
}
public int reverse(int num)
{
int rev;
String r = "";
String n = Integer.toString(num);
int len = n.length();
for(int i = len-1;i>=0;i--)
{
r+=n.charAt(i)+"";
}
rev = Integer.valueOf(r);
return rev;
}
public void revMat(MatRev num)
{
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
this.arr[i][j] = reverse(num.arr[i][j]);
}
}
}
public void show()
{
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int x = sc.nextInt();
System.out.print("Enter number of columns: ");
int y = sc.nextInt();
MatRev ob1 = new MatRev(x, y);
MatRev ob2 = new MatRev(x, y);
ob1.fillArray();
ob2.revMat(ob1);
System.out.println("Original Matrix");
ob1.show();
System.out.println("Matrix with reversed elements");
ob2.show();
}
}Output:
Enter number of rows: 3
Enter number of columns: 3
Original Matrix
72 371 5
12 6 426
5 123 94
Matrix with reversed elements
27 173 5
21 6 624
5 321 49
For other number related programs check the given link
Unleashed: Important Number Programs for ICSE Part-1
Related Posts
Continue learning with these related articles

Logic Gates for ISC Class 11: Truth Tables, Universal Gates, Half and Full Adder
ISC Class 11 Computer Science notes on logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR with truth tables, why NAND and NOR are universal gates, and half adder and full adder circuits with their Boolean expressions.
Decimal to Binary Conversion in Java: 3 Programs with Examples
How to convert a decimal number to binary on paper and in Java: three programs (String, place value and Integer.toBinaryString), binary to decimal, a dry run and common mistakes.

ISC Class 11 Computer Science Sample Paper 2026-27 with Solutions
A full 70-mark ISC Class 11 Computer Science sample paper for the 2026-27 annual exam: MCQs, number systems, propositional logic, logic gates, Java classes, arrays, strings, searching and sorting, and computing ethics, with complete worked solutions.