Mirror Image of a Matrix
Finding Mirror image of a matrix of order M X N is given.
Logic and Program :-
Logic :-
Program :-
import java.io.*; import java.util.*; class Mirror { public static void main(String args[]) { Scanner in=new Scanner(System.in); int m,n,i,j,k,temp; System.out.println("Enter Array Capacity"); m=in.nextInt(); // Storing capacity of Rows n=in.nextInt(); // Storing capacity of Columns int ar[][]=new int[m][n]; // For Original Matrix int br[][]=new int[m][n]; // For Mirror Matrix k=n-1; // variable for swapping System.out.println("Enter Array Elements"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { ar[i][j]=in.nextInt(); // Entering Matrix Elements } } System.out.println("Original Matrix"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { System.out.print(ar[i][j]+"\t"); // Displaying Original Matrix } System.out.println(); } for(i=0;i<m;i++) { for(j=0;j<n;j++) { br[i][j]=ar[i][k-j]; // Swapping the Matrix Elements } } System.out.println("Mirror Matrix"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { System.out.print(br[i][j]+"\t"); // Displaying Mirror Matrix } System.out.println(); } } // end of main method } // end of class
Note : The program is written in the easiest way possible so try understand it. If you face any problem in understanding this program than feel free to contact/comment.
All the Best :)
Keep Learning :)
Comments