visitnag
10/14/2014 2:22:00 PM
On Tuesday, 14 October 2014 19:38:45 UTC+5:30, Varun wrote:
> Hi,
>
> I have written the following code on sorting of strings but the output is not proper.Please help...
>
>
>
> import java.io.*;
>
> class sort
>
> {
>
> public static void main()throws IOException
>
> {
>
> InputStreamReader isr=new InputStreamReader(System.in);
>
> BufferedReader br=new BufferedReader(isr);
>
> int i,j;
>
> String a[]=new String[5];
>
> a[0]="Varun";
>
> a[1]="Nagar";
>
> a[2]="Kvars";
>
> a[3]="Hemaa";
>
> a[4]="Jayaa";
>
>
>
> int l=a.length;
>
> for(j=0;j<l-1;j++)
>
> {
>
> for(i=0;i<l-1;i++)
>
> {
>
> if((a[i+1].compareTo(a[i])>0))
Change the ">" sign to "<"
>
> {
>
> String t=a[i];
>
> a[i]=a[i+1];
>
> a[i+1]=t;
>
> }
>
> }
>
> }
>
> System.out.println("the sorted array===");
>
> for(i=0;i<5;i++)
>
> {
>
> System.out.println(a[i]);
>
> }
>
> }
>
> }