[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

string sorting not working properly

k.varunshastry

10/14/2014 2:09:00 PM

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]);
}
}
}



4 Answers

visitnag

10/14/2014 2:22:00 PM

0

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]);
>
> }
>
> }
>
> }

Evertjan.

10/14/2014 2:35:00 PM

0

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)

Scott Sauyet

10/14/2014 6:43:00 PM

0

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

Denis McMahon

10/14/2014 11:31:00 PM

0

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