0% found this document useful (0 votes)
8 views2 pages

Rotation Matrix 270

program of rotation matrix (class 12 computer science)
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Rotation Matrix 270

program of rotation matrix (class 12 computer science)
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

package array;

import java.util.*;
public class Rotate2
{
public static void main(String[] args)
{
// Accepting the number of rows and columns
Scanner sc = new Scanner (System.in);
System.out.println("ENTER THE NUMBER OF ROWS :");
int m = sc.nextInt();
System.out.println("ENTER THE NUMBER OF COLUMNS : ");
int n = sc.nextInt();
if ((m>2&&m<10)||(n>2&&n<10))
{
//initializing an array
int A[][] = new int[m][n];

for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.println("ENTER ELEMENTS");
A[i][j]=sc.nextInt();
}
}
//Displaying original matrix
System.out.println("ORIGINAL MATRIX ");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(A[i][j]+"\t");
}
System.out.println();
}
//Displaying rotated matrix
System.out.println("ROTATED MATRIX ");

for(int i=0;i<n;i++)
{
for(int j=m-1;j>=0;j--)
{
System.out.print(A[j][i]+"\t");
}
System.out.println();
}

int sum = 0;

for (int i=0;i<m;i++)


{
for (int j=0;j<n;j++)
{
if (A[i][j]%2!=0)
{
sum = sum + A[i][j];
}
}
}
//Displaying the sum of original matrix
System.out.println("SUM OF ODD ELEMENTS " +sum);
}
else
{
System.out.println("INVALID INPUT");
}
}
}

You might also like