This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes sorting an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sorting an array" Watch "sorting an array" New topic
Author

sorting an array

Michael Taylor
Greenhorn

Joined: Jun 19, 2002
Posts: 15
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

Joined: Dec 10, 2001
Posts: 7023
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!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Owee Nicolas
Ranch Hand

Joined: Jun 16, 2002
Posts: 49
You may want to check out this link about the different Sorting Algorithms.


Owee<br />SCJP 1.4
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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

Joined: Jan 13, 2002
Posts: 479
Hi Nicolas,
your link is nice, maybe you got other links which explain those Algorithms. Thx a lot!


Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
Michael Taylor
Greenhorn

Joined: Jun 19, 2002
Posts: 15
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

Joined: Feb 22, 2001
Posts: 156
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

Joined: Jun 19, 2002
Posts: 15
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: sorting an array
 
Similar Threads
Remove duplicates in an Arrays
Creating an array from part of a string
socket programming
Finding the Median
Meaningful 2D array sort?