Rotate a Matrix by 90 degree
Rotate a Matrix by 90 degree: solved Java program for ISC Class 11 Computer Science with complete BlueJ code, explanation and sample output.
Watch java videos
Write a program to rotate a matrix (square matrix N x N) by 90 degrees (clockwise).

import java.io.*;
class RotateMatrix
{
int r;
int Arr[][];
int NewA[][];
void fill_array()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the order of the matrix");
r=Integer.parseInt(br.readLine());
Arr=new int[r][r];
NewA=new int[r][r];
System.out.println("ENTER THE VALUES OF THE ARRAY");
for(int i=0;i<r;i++)
{
for(int j=0;j<r;j++)
{
Arr[i][j]=Integer.parseInt(br.readLine());
}
}
}
void tilt()
{
for(int i=0;i<r;i++)
{
int k=0;
for(int j=(r-1);j>=0;j--)
{
NewA[i][j]=Arr[k][i];
k++;
}
}
}
void display()
{
System.out.println("----------THE ORIGINAL MATRIX---------------");
for(int i=0;i<r;i++)
{
for(int j=0;j<r;j++)
{
System.out.print(Arr[i][j]+"\t");
}
System.out.println();
}
System.out.println("----------THE 90% TILTED MATRIX---------------");
for(int a=0;a<r;a++)
{
for(int b=0;b<r;b++)
{
System.out.print(NewA[a][b]+"\t");
}
System.out.println();
}
}
public static void main()throws IOException
{
RotateMatrix obj=new RotateMatrix();
obj.fill_array();
obj.tilt();
obj.display();
}
}Download free Sample papers
Output:
Enter the order of the matrix
3
ENTER THE VALUES OF THE ARRAY
1
2
3
4
5
6
7
8
9
----------THE ORIGINAL MATRIX---------------
1 2 3
4 5 6
7 8 9
----------THE 90% TILTED MATRIX---------------
7 4 1
8 5 2
9 6 3
Related Posts
Continue learning with these related articles

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.

Boolean Algebra for ISC Class 12: Laws, Canonical SOP and POS, and Simplification
ISC Class 12 Computer Science notes on Boolean algebra: all the laws and theorems, duality, De Morgan's laws, minterms and maxterms, converting to canonical SOP and POS, and step-by-step algebraic simplification with solved examples.