Friday, October 21, 2011

Bubble Sort{Alphabets}

import java.io.*;
class BubbleSortAlpha
{
    public static void main(String args[])throws IOException
    {
        InputStreamReader reader=new InputStreamReader(System.in);
        BufferedReader input=new BufferedReader(reader);
        System.out.println("ENTER TEN STRINGS");
        String a[]=new String[10];
        String temp;
       for(int i=0;i<10;i++)
       a[i]=input.readLine();
       for(int i=0;i<10;i++)
       {
           for(int j=0;j<9-i;j++)
           {
               if((a[j+1].compareTo(a[j]))<0)
               {
                   temp=a[j+1];
                   a[j+1]=a[j];
                   a[j]=temp;
                }
            }
        }
        System.out.println("AFTER SORTING THE SEQUENCE IS");
        for(int i=0;i<10;i++)
        System.out.println(a[i]);
    }
}
      
      
       

No comments:

Post a Comment