Here is the Program to sort non-boundary elements of matrix in Descending order JAVA. This program is one of the most important and quite easy program for ISC 2021 Board Exams because every year, one program of this type is asked by council in Board examination. All the matrix based programs are inter-related to each other so it will be an advantage for you if you practice these type of programs, you will perform very well in boards and in computer practical as well.
Checkout:- Neon Number In Java - Solved Program
Checkout:- Spy Number In Java - Solved Program
We are uploading these types of program. However, if you need fully compiled solution of any type of Java program then simply leave a comment below, we will help you at the earliest. 😊😊
import java.util.*;
class Selecton_Sort_Descending_Order_Non_Boundary_Elements_Matrix
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int arr[][]=new int[10][10];
int brr[]=new int[10*10];
int n=0;
System.out.print("INPUT:M=");
int M=sc.nextInt();
if(M<4||M>10)
System.out.println("THE MATRIX SIZE IS OUT OF RANGE");
else
for(int i=0;i<M;i++)
{
for(int j=0;j<M;j++)
{
System.out.print("Input a Element for Matrix:");
arr[i][j]=sc.nextInt();
}
}
System.out.println("OUTPUT:\nORIGINAL MATRIX");
for(int i=0;i<M;i++)
{
for(int j=0;j<M;j++)
{
System.out.print(arr[i][j]+"\t");
if(i!=0 && j!=0 && i!=M-1 && j!=M-1)
{
brr[n++]=arr[i][j];
}
}
System.out.println(" ");
}
for(int i=0;i<n-1;i++)
{
int smallest=brr[i];
int pos=i;
for(int j=i+1;j<n;j++)
{
if(brr[j]>smallest)
{
smallest=brr[j];
pos=j;
}
}
brr[pos]=brr[i];
brr[i]=smallest;
}
n=0;
for(int i=0;i<M;i++)
{
for(int j=0;j<M;j++)
{
if(i!=0 && j!=0 && i!=M-1 && j!=M-1)
{
arr[i][j]=brr[n++];
}
}
}
System.out.println("REARRANGED MATRIX");
for(int i=0;i<M;i++)
{
for(int j=0;j<M;j++)
{
System.out.print(arr[i][j]+"\t");
}
System.out.println(" ");
}
}
}
-----------
OUTPUT:-
-----------
INPUT:M=4
Input a Element for Matrix:1
Input a Element for Matrix:5
Input a Element for Matrix:4
Input a Element for Matrix:2
Input a Element for Matrix:6
Input a Element for Matrix:8
Input a Element for Matrix:7
Input a Element for Matrix:5
Input a Element for Matrix:2
Input a Element for Matrix:4
Input a Element for Matrix:6
Input a Element for Matrix:9
Input a Element for Matrix:1
Input a Element for Matrix:2
Input a Element for Matrix:5
Input a Element for Matrix:4
OUTPUT:
ORIGINAL MATRIX
1 5 4 2
6 8 7 5
2 4 6 9
1 2 5 4
REARRANGED MATRIX
1 5 4 2
6 8 7 5
2 6 4 9
1 2 5 4
0 Comments
Just write down your question to get the answer...