0% found this document useful (0 votes)
21 views1 page

Mirror Matrix

Uploaded by

subhodip.das.jmi
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)
21 views1 page

Mirror Matrix

Uploaded by

subhodip.das.jmi
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

1

2 /**
3 * Matrix mirror as per concept
4 *
5 * @Subhodip Das
6 * @19-07-2024
7 */
8 import java.util.Scanner;
9 public class mirror
10 {
11 public static void main(String args[]) {
12 Scanner in = new Scanner(System.in);
13 //INITIALIZING THE ARRAY DIMENTION FOR ROW AND COLUMN
14 System.out.print("Enter number of rows (m): ");
15 int m = in.nextInt();
16 System.out.print("Enter number of columns (n): ");
17 int n = in.nextInt();
18 int arr[][] = new int[m][n];
19 int newArr[][] = new int[m][n];
20 //INITIALIZING THE ARRAY ELEMENTS
21 System.out.println("Enter array elements");
22 for (int i = 0; i < m; i++)
23 {
24 System.out.println("Enter Row "+ (i+1) + " :");
25 for (int j = 0; j < n; j++)
26 {
27 arr[i][j] = in.nextInt();
28 }
29 //System.out.println(" ");
30 }
31 //DISPLAY THE INPUT ARRAY WITH ESCAPE SEQUENCE AS TAB
32 System.out.println("Input Array:");
33 for (int i = 0; i < m; i++)
34 {
35 for (int j = 0; j < n; j++)
36 {
37 System.out.print(arr[i][j] + "\t");
38 }
39 System.out.println();
40 }
41 //SWAPPING THE ELEMENTS FOR THE MIRROR IMAGE CONVERTION
42 for (int j = 0; j < n; j++)
43 {
44 for (int i = 0; i < m; i++)
45 {
46 newArr[i][n - 1 - j] = arr[i][j];
47 }
48 }
49 //DISPLAY THE OUTPUT AS MIRROR IMAGE
50 System.out.println("Mirror Image Array:");
51 for (int i = 0; i < m; i++)
52 {
53 for (int j = 0; j < n; j++)
54 {
55 System.out.print(newArr[i][j] + "\t");
56 }
57 System.out.println();
58 }
59 }
60 }
61

You might also like