Skip to main content

Let's CODE IT...Bubble Sort In Matrix Ascending Order

Let's do this in easiest way.....
ISC Practical 2020

****************************
HERE IS THE CODE:
****************************
import java.util.*;
public class Bubble_Sort_In_Matrix_Ascending_Order
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        int n=0,temp,i,j;
        System.out.println("Enter the number of Rows");
        int r=sc.nextInt();
        System.out.println("Enter the number of Columns");
        int c=sc.nextInt();
        int arr[][]=new int[r][c];
        int brr[]=new int[r*c];
        System.out.println("Enter the elements of Matrix");
        for( i=0;i<r;i++)
        {
            for( j=0;j<c;j++)
            {               
                arr[i][j]=sc.nextInt();
            }            
        }
        System.out.println("INPUT MATRIX IS:-");
        for(i=0;i<r;i++)
        {
            for(j=0;j<c;j++)
            {  
                brr[n++]=arr[i][j];
                System.out.print(arr[i][j]+" ");                 
            } 
            System.out.println(""); 
        }
        for(int l=0;l<n-1;l++)
        {
            for(int k=0;k<n-1;k++)
            {
                if(brr[k]>brr[k+1])
                {
                    temp=brr[k];
                    brr[k]=brr[k+1];
                    brr[k+1]=temp;
                }
            }
        }
        n=0;
        for(i=0;i<r;i++)
        {
            for(j=0;j<c;j++)
            {                
                arr[i][j]=brr[n++];                 
            }           
        }
        System.out.println("REARRANGED MATRIX IS:-");
        for(i=0;i<r;i++)
        {
            for(j=0;j<c;j++)
            {         
                System.out.print(arr[i][j]+" ");
            }
            System.out.println("");
        }
    }
}
****************************************************************************

OUTPUT:

------------


Comments

Popular posts from this blog

How to fix/solve Compilation Error in Python

A Quick Overview on Compilation Error A Compilation Error is a special type of error that occurs while using Python as Source Code. The main reason behind this error is that python is an interpreted language. So, the online judge rather than interpreting it compiles the code and hence the error occurs. The best approach to tackle these kind of problems is either use a compilation command or convert the program in single line using the single function containing the whole program For.e.g., Program to convert a character in LowerCase at a specified place. def mains():                    //Driver Function     n,K=input().split()     n=int(n)     K=int(K)     S=input()     print(S[:(K-1)]+chr(ord(S[K-1])+32)+S[(K):]) mains() Input: 4 3 TEAM Output: TEaM Hope this articles ...

Technical Knowledge

A  feature phone  is a  mobile phone  that retains the  form factor  of earlier-generation phones, with button-based input and a small display. Feature phones are sometimes called  dumbphones  in contrast with touch-input  smartphones . [1]  They tend to use an  embedded operating system  with a small and simple  graphical user interface , unlike large and complex general-purpose  mobile operating systems  like  Android  or  iOS . Feature phones typically provide  voice calling  and  text messaging  functionality as well as basic  multimedia  and  Internet  capabilities and other services offered by the user's  wireless service provider . Feature phones have a backlit  LCD  screen, a hardware  notification LED , and  micro USB  port and have a physical keyboard, a microphone,  SD card  slot, a rear-facing camera to...

ISC Computer Science-2020 Paper 2(Theory) Q7. Solved

Computer Science Paper -(ISC Programs 2020) Write a program in JAVA to to find the date and the month from a given day number for a particular year. For e.g.  Year: 2020 Day: 64 March 4, 2020     ----------------------------------------------------------------------      import java.util.*; public class Q_7 {     public static void main(String args[])     {         Scanner sc=new Scanner(System.in);         System.out.println("Year : ");         int i,f,s;         int year=sc.nextInt();         System.out.println("Day : ");         int d=sc.nextInt();         int a[]={31,28,31,30,31,30,31,31,30,31,30,31};         String b[]={"January","February","March","April","May","June","July","August","September","October","November","December"}; ...