Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sorting an array

 
Michael Taylor
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the best way to sort an array?
I want the user to input some integers, in any random order, have the numbers put in numerical order, then show the middle number.
One step further would be if the user entered an even number of integers, after the sort, have the two middle integers combined to output the mean of those numbers.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
t-bird69,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
Owee Nicolas
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to check out this link about the different Sorting Algorithms.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your goal to learn about sorting algorithms?
What have you tried so far?
Post your code, and don't forget to surround the code with the [code] and [/code] UBB tags in order to preserve formatting.
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nicolas,
your link is nice, maybe you got other links which explain those Algorithms. Thx a lot!
 
Michael Taylor
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code that I have. What I am trying to do with this is have the user enter a sentence, then enter a letter. I want my program to take the letter entered, search the string for that letter and display how many times the letter is in the sentence entered.

[ edited to prevent left-right scrolling -ds ]
[ June 20, 2002: Message edited by: Dirk Schreckmann ]
 
Angela Lamb
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Didn't your first post say you were trying to sort an array of integers? What does the code you posted have to do with sorting?
Anyway, here is one way to count the number of times that a letter occurs in a sentence:
 
Michael Taylor
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angela,
Thanks for the help. It works great. In my first post I was thinking I wanted to enter my string into an array and then sort it by character that way. I am very new to Java, and appreciate your information very much.
Michael
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic