Check Rotated Matrix Equality (270 Degrees)
This program checks if one matrix is rotation of another by 270 degrees.
Problem Statement
Write a Java program to check whether matrix B is rotation of matrix A by 270 degrees.
Source Code
| 1 | public class MatrixRotation270Check { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Matrix Rotation 270 Check"); |
| 4 | int[][] A = {{1,2,3},{4,5,6},{7,8,9}}; |
| 5 | int[][] B = {{3,6,9},{2,5,8},{1,4,7}}; |
| 6 | boolean rotated=true; |
| 7 | for(int i=0;i<3;i++){ |
| 8 | for(int j=0;j<3;j++){ |
| 9 | if(B[i][j]!=A[j][3-1-i]) rotated=false; |
| 10 | } |
| 11 | } |
| 12 | if(rotated) System.out.println("Matrix B is 270-degree rotation of A"); |
| 13 | else System.out.println("Matrix B is not rotation of A"); |
| 14 | } |
| 15 | } |
Program Output
Eduinq Matrix Rotation 270 Check Matrix B is 270-degree rotation of A
Explanation
Rotation by 270 degrees clockwise, equivalent to 90 degrees counter-clockwise, is checked using B[i][j] == A[j][n-1-i], and nested loops validate this equality condition, demonstrating a rotated matrix equality check.