Define a class to accept 10 integers and arrange them in descending order using bubble sort. Print the original array and the sorted array. 
    
Solution:
Define a class to accept 10 integers and arrange them in descending order using bubble sort. Print the original array and the sorted array. Define a class to accept 10 integers and arrange them in descending order using bubble sort. Print the original array and the sorted array. Define a class to accept 10 integers and arrange them in descending order using bubble sort. Print the original array and the sorted array.
 

import java.util.*;
class BubbleSort
{
public static void main(String args[])
{   int temp;
    int a[]=new int[10];
    Scanner sc=new Scanner(System.in);
    for(int i=0;i< 10;i++)
    {
        System.out.println("Enter the "+(i+1)+" element:");
        a[i]=sc.nextInt();
    }

    //display array
    System.out.println("Original array is:");
    for (int i = 0; i < 10; i++)
    {

        System.out.print(a[i] +" ");
    }

    for(int i=0; i < a.length; i++)
    {  
        for(int j=0; j < a.length-i-1; j++){  
            if(a[j] < a[j+1]){  

                //swap elements  
                temp = a[j];  
                a[j] = a[j+1];  
                a[j+1] = temp;  
            }  

        }  
    }  
    System.out.println("
  Sorted array is:");

    for (int i=0;i< 10;i++)
    {
        System.out.print(a[i] +" ");
    }
}
}
                                                                          


                                            



Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com