The Artima Developer Community
Sponsored Link

Java Answers Forum
what's wrong in this code????? urgently help required

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
anoria

Posts: 3
Nickname: anorita
Registered: Aug, 2005

what's wrong in this code????? urgently help required Posted: Aug 21, 2005 2:00 AM
Reply to this message Reply
Advertisement
I WANT HELP ON THE FOLLOWING SORTING CODE.
PROBLEM IS THAT I WANT TO SORT THE CHARACTERS IN STRING.
1ST I CONVERTED STRING IN CHAR[] ARRAY THEN I TRY TO SORT CHAR[] ARRAY. AND THEN I CONVERTED THAT CHAR BACK INTO STRING .....

public class StringSort
{
public static String s1,s2;
public static int k;
public static char x,z;
public static char[] temp2;


public void sort() throws IOException
{
s1="tola";
k=s1.length();
char[] texttemp=s1.toCharArray();// t,o,l,a
for (int p=0;p<k;p++)
{
x=texttemp[p];
z=texttemp[p+1];
if (x<z)
{
temp2[k]=x; //t,o
temp2[k+1]=z;
}
else
{
temp2[k]=z;//o,t
temp2[k+1]=x;
}

}

s2=String.copyValueOf(temp2);//converting char to string
System.out.print(" sorted characters in string is "+s2);

}
public static void main(String[] args)
{



AnagramsII ana=new AnagramsII();
try{
ana.StringSort();
}catch (IOException ex)
{System.out.print(" xxxxx ");}


}

}

Topic: Java IO problems Previous Topic   Next Topic Topic: how should i append data to file by overwriting the one's already existing?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use