Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  SortString
Language: JAVA
Code:
class SortString
{
    public static void main(String args[])
    {
        int n,i,j;
        String st[]=new String[10];
        String temp=" ";
        n=args.length;
        for(i=0;i<n;i++)
            st[i]=args[i];
        System.out.println("INPUT STRINGS");
        for(i=0;i<n;i++)
        {
            System.out.println(st[i]);
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<n-i-1;j++)
            {
                if(st[j].compareTo(st[j+1])>0)
                {
                    temp=st[j];
                    st[j]=st[j+1];
                    st[j+1]=temp;
                }
            }
        }
        System.out.println("SORTED STRINGS");
        for(i=0;i<n;i++)
        {
            System.out.println(st[i]);
        }
    }
}
Comments: