document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.util.Scanner;
  2. class Bubble
  3. {
  4.     public static void main(String args[])
  5.     {
  6.         Scanner ip=new Scanner(System.in);
  7.         System.out.println("enter the number length of array");
  8.         int x=ip.nextInt();
  9.         int arr[]=new int[x];
  10.         //entering elements into the array
  11.         System.out.println("Enter the elements now");
  12.         for(int i=0;i<x;i++)
  13.         {
  14.             arr[i]=ip.nextInt();
  15.         }
  16.        
  17.         //bubble sort
  18.        
  19.         for(int i=0;i<x;i++)
  20.         {
  21.             for(int j=0;j<x-i-1;j++)
  22.             {
  23.                 if(arr[j]>arr[j+1])//swap condition
  24.                 {
  25.                     int temp=arr[j];
  26.                     arr[j]=arr[j+1];
  27.                     arr[j+1]=temp;
  28.                 }
  29.             }
  30.         }
  31.         System.out.println("the array in the sorted order is :");
  32.         for(int i=0;i<x;i++)
  33.         {
  34.             System.out.println(arr[i]);
  35.         }
  36.     }
  37.    
  38. }
');