0% found this document useful (0 votes)
25 views2 pages

Class Matrix - Image: Nov 27, 2014 8:32:05 PM

The document defines a Java class called matrix_image that represents a 2D matrix. The class contains methods to initialize the matrix, get user input to populate the matrix elements, create a mirror image of the matrix by flipping elements across the main diagonal, and output the original and mirrored matrices. A main method is included to demonstrate executing the class by getting the matrix size, populating the matrix, creating the mirror, and displaying the results.

Uploaded by

prasoonBatham911
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

Class Matrix - Image: Nov 27, 2014 8:32:05 PM

The document defines a Java class called matrix_image that represents a 2D matrix. The class contains methods to initialize the matrix, get user input to populate the matrix elements, create a mirror image of the matrix by flipping elements across the main diagonal, and output the original and mirrored matrices. A main method is included to demonstrate executing the class by getting the matrix size, populating the matrix, creating the mirror, and displaying the results.

Uploaded by

prasoonBatham911
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Class matrix_image

1/2

import java.io.*;
class matrix_image
{
double arr1[][]=new double[15][15];
double arr2[][]=new double[15][15];
int m,n;//integers to store number of rows and columns
matrix_image()
{
for(int i=0;i<15;i++)
{
for(int j=0;j<15;j++)
{
arr1[i][j]=0;
arr2[i][j]=0;
}
}
m=0;
n=0;
}
//storing actual rows and columns
matrix_image(int mm,int nn)
{
m=mm;
n=nn;
}
void getmat()throws IOException
{
DataInputStream d=new DataInputStream(System.in);
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.println("ENTER ELEMENT ON ADDRESS "+i+","+j);
arr1[i][j]=Integer.parseInt(d.readLine());
}
}
}
void mirror_image()
{
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
arr2[i][n-1-j]=arr1[i][j];
}
}
}
void show()
{
Nov 27, 2014 8:32:05 PM

Class matrix_image (continued)

2/2

System.out.println("MATRIX INPUTED");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(arr1[i][j]+" ");
}
System.out.println();
}
System.out.println("MIRROR IMAGE OF THE MATRIX INPUTED");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(arr2[i][j]+" ");
}
System.out.println();
}
}
/*main not specified in question
* but still written to bring out
* the execution of program.
*/
void main()throws IOException
{
DataInputStream d=new DataInputStream(System.in);
System.out.println("Enter number of rows");
int m=Integer.parseInt(d.readLine());
System.out.println("Enter number of columns");
int n=Integer.parseInt(d.readLine());
matrix_image mi=new matrix_image(m,n);
mi.getmat();
mi.mirror_image();
mi.show();
}
}

Nov 27, 2014 8:32:05 PM

You might also like