• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java program help  RSS feed

 
richard chuquilin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys i need help with one question. I want to sort a list of strings WITHOUT using any sort method of the Array class (or any other Java library sorting Class). The list must be ALPHABETIZE.

My code is :

public class Strings
{



public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);

System.out.print("Enter the strings > ");
String s1 = new String(reader.nextLine());

String[] t1 = s1.split(",");

for (String t: t1)
{
System.out.println(t);
}
}


}

 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what's the one question?
 
richard chuquilin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I sort the the list of strings without using any sort methods? The list must be alphabetize.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12562
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) turn off your computer
2) get paper and pencil
3) Work out how YOU would sort a list, using only the above paper and pencil
4) revise the above steps, until they are simple enough for a 10 year old child to follow.

Only once you've done that should you consider writing a single line of code.

Once you start writing code, do not write more than 2-3 lines before you re-compile and TEST TEST TEST.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

When you do start writing code, don't write new String(...); The method you are using already returns a String so new String is pointless.
 
Robert D. Smith
Ranch Hand
Posts: 221
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java tutorials at Oracle is a good place to begin.

http://docs.oracle.com/javase/tutorial/collections/algorithms/

To get you started.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a good link, but it does not tell anybody how the sorting is done. One might have to write one's own sorting methods. Somebody else asked a similar question last week; it might be worth reading their thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!