The Artima Developer Community
Sponsored Link

Java Answers Forum
what's wrong in this code???

2 replies on 1 page. Most recent reply: Aug 22, 2005 1:22 PM by Matt Gerrans

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 2 replies on 1 page
anoria

Posts: 3
Nickname: anorita
Registered: Aug, 2005

what's wrong in this code??? Posted: Aug 21, 2005 2:03 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 ..... it gives an nullpointer exception

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)
{



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


}

}


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: what's wrong in this code??? Posted: Aug 21, 2005 10:45 PM
Reply to this message Reply
Format that code properly and someone might bother
to respond to your post. This topic of coding formatting
has been beaten to death, personal I'm not even going
to spend 5 seconds looking at your ill-presented code!!!

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: what's wrong in this code??? Posted: Aug 22, 2005 1:22 PM
Reply to this message Reply
I think the big problem with this code is that it doesn't use the library sort() routine.

ALSO, THERE IS NOTHING MORE ANNOYING THAN QUESTIONS POSTED IN ALL CAPS.

Flat View: This topic has 2 replies on 1 page
Topic: what's wrong in this code????? urgently help required Previous Topic   Next Topic Topic: Java IO problems

Sponsored Links



Google
  Web Artima.com   

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