java - single string list- alphabetizing -


i'm trying write code uses scanner input list of words, in 1 string, alphabetizer each individual word. i'm getting first word alphabetized letter, how can fix this?

the code:

else if(answer.equals("new"))     {       system.out.println("enter words, separated commas , spaces.");       string input= scanner.next();       char[] words= input.tochararray();        arrays.sort(words);       string sorted= new string(words);       system.out.println(sorted);      } 

result: " ,ahy "

you're reading in string via scanner.next() , breaking string characters. so, said, it's sorting single-string characters via input.tochararray(). need read in of words , add them string []. after of words have been added, use arrays.sort(yourstringarray) sort them. see comments answers following questions.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -