Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #25903 > unrolled thread

string sorting not working properly

Started byk.varunshastry@gmail.com
First post2014-10-14 07:08 -0700
Last post2014-10-14 23:30 +0000
Articles 5 — 5 participants

Back to article view | Back to comp.lang.javascript


Contents

  string sorting not working properly k.varunshastry@gmail.com - 2014-10-14 07:08 -0700
    Re: string sorting not working properly visitnag@gmail.com - 2014-10-14 07:21 -0700
    Re: string sorting not working properly "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-10-14 16:35 +0200
    Re: string sorting not working properly Scott Sauyet <scott.sauyet@gmail.com> - 2014-10-14 11:42 -0700
    Re: string sorting not working properly Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-14 23:30 +0000

#25903 — string sorting not working properly

Fromk.varunshastry@gmail.com
Date2014-10-14 07:08 -0700
Subjectstring sorting not working properly
Message-ID<d4d590e4-d6e2-4222-8862-d88a382bd7c2@googlegroups.com>
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))
                {
                    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]);
            }
        }
    }
                
        
            

[toc] | [next] | [standalone]


#25904

Fromvisitnag@gmail.com
Date2014-10-14 07:21 -0700
Message-ID<0f6b18d0-d625-4882-b1ff-cfa6329c66e9@googlegroups.com>
In reply to#25903
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]);
> 
>             }
> 
>         }
> 
>     }

[toc] | [prev] | [next] | [standalone]


#25906

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-10-14 16:35 +0200
Message-ID<XnsA3C6A8B96DD73eejj99@194.109.133.133>
In reply to#25903
k.varunshastry@gmail.com wrote on 14 okt 2014 in comp.lang.javascript:

> I have written the following code on sorting of strings but the output
> is not proper.Please help... 
> 
> import java.io.*;

This NG is about javascript scripting,
not about java scripting.

So even your Q is not proper.

Please go elsewhere.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#25907

FromScott Sauyet <scott.sauyet@gmail.com>
Date2014-10-14 11:42 -0700
Message-ID<a6842a1f-e269-4052-b107-0461fe8038cb@googlegroups.com>
In reply to#25903
Varun wrote:
> 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
> // ...

This newsgroup is for discussions on Javascript, which, despite similarities 
in the names, has nothing whatsoever to do with the Java programming
language.

You might check out comp.lang.java or related NGs.

  -- Scott

[toc] | [prev] | [next] | [standalone]


#25909

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-10-14 23:30 +0000
Message-ID<m1kbn4$jfo$3@dont-email.me>
In reply to#25903
On Tue, 14 Oct 2014 07:08:37 -0700, k.varunshastry wrote:

> I have written the following code on sorting of strings but the output
> is not proper.Please help...
> 
> import java.io.*;

This is a javascript newsgroup. Not a java one.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web