You are on page 1of 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