Document 1
Document 1
Write a program to declare a Square, Matrixx a[][] of order m*n where ‘m’ is the number of rows and ‘n’ is
the number of columns, such that m and n both must be greater than 2 and less than 10 . accept the value of m
and n as user input. Allow the user to input the integers into Matrixx and perform the following task.
1. Display the original Matrixx
Original Matrixx:
1 2 3 4
5 6 7 8
9 10 11 12
choice =sc.nextInt();
if(choice==1)
{
int c[][] = new int[n][m]; //creating a new array to store the rotated matrix-clockwise
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
c[j][m - 1 - i] = a[i][j]; //rotating the matrix
}
}
System.out.println("Rotated matrix (90° clockwise):");
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
System.out.print(c[i][j] + "\t"); // printing, the rotated Matrix
}
System.out.println();
}
}
else if(choice==2)
{
int ac[][] = new int[n][m]; //creating a new array to store the rotated matrix-anticlockwise
else
{
System.out.println("invalid array input");
}
}
}
Write a program to declare a Square Matrixx, a [][] order m*n where m is the number of rows and n is the
number of columns such that m and n both must be greater than 2 and less than 10 . Accept the value of ‘m’ and
‘n’ as user input and perform the following task.
Display the original Matrixx.
Sort each column of the matrix in ascending order using selection sort technique.
Play the changed Matrixx after sorting each row.
Test your program for the following data and some random data:
Example 1:
Input:
m=4
n=3
Enter the element of matrix:
11 -2 3 5 16 7 9 0 4 3 1 8
OUTPUT:
ORIGINAL MATRIX:
11 -2 3
5 16 7
9 0 4
3 1 8
MATRIX AFTER SORTING:
3 -2 3
5 0 4
9 1 7
11 16 8
Example 2:
INPUT:
m=11
n=5
OUTPUT:
Metric size out of range.
Program 18:Code:
System.out.println("Original Matrixx:");
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
System.out.print(a[i][j] + "\t"); //Printing the original Matrixx
}
System.out.println();
}