-
Sorting from an array
Here is my code:
Code:
public class letterpuzzle {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
char choice;
/**
* The code below declares what is a vowel or consonant
*/
char[] con = { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n',
'p', 'q', 'u', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z' };
char[] vow = { 'a', 'e', 'i', 'o', 'u' };
// TextIO.readFile("words.txt");
/**
* This part of the program asks the user to choose a vowel or consonant
* by pressing C or V. Then randomly picks a vowel or consonant
* depending on what letter was pressed.
*/
char[] letters = new char[8];
for (int i = 0; i < letters.length; i++) {
TextIO.put("Do you want a consonant or a vowel?");
choice = TextIO.getlnChar();
if (choice == 'v')
letters[i] = vow[(int) (Math.random() * 4)];
else
letters[i] = con[(int) (Math.random() * 20)];
}
}
}
What I need to do is take the letters that are randomly picked and stored and then sort them into a word (longest word/s) against the file "words.txt" and then display that word. The easiest way we were told was to use a bubble sort, I'm just not sure how to apply it to the code so far.
Any help or solutions would be greatly appreciated.
-
Re: Help with Sorting
Please go through http://www.java-forums.org/forum-gui...w-members.html and BB Code List - Java Programming Forum and edit your post accordingly.
You didn't bother to return to the first thread you started. Why should we expect any better behavior this time round?
db
-
Re: Help with Sorting
I've edited the post to go along with the rules. The last post was during a class and I was able to work out what I needed to do and forgot I posted on this forum. Sorry for leaving that post without a response.