class StringTest
{
                static String name[]={"Vivek","Lalit","Prince","Aruni","Sachin","Phrabhat","Vikrant"};
                public static void main(String args[])
                {
                                String temp=null;
                                int size=name.length;
                                for(int i=0;i<size-1;i++)
                                {
                                                for(int j=i+1;j<size;j++)
                                                {
                                                                if(name[j].compareTo(name[i])<0)
                                                                {
                                                                                temp=name[i];
                                                                                name[i]=name[j];
                                                                                name[j]=temp;
                                                                }
                                                }
                                }
                for(int i=0;i<size;i++)
                                System.out.println(name[i]);
                }
}

JAVA 28.PNG

Advertisements