Results 1 to 3 of 3
Thread: Help with Sorting
- 12-06-2012, 02:09 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 4
- Rep Power
- 0
Sorting from an array
Here is my code:
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.Java 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)]; } } }
Any help or solutions would be greatly appreciated.Last edited by Acaul; 12-07-2012 at 11:08 AM.
- 12-06-2012, 03:27 PM #2
Re: Help with Sorting
Please go through Guide For New Members 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?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-07-2012, 11:06 AM #3
Member
- Join Date
- Nov 2012
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
C# Sorting
By larry_d1990 in forum New To JavaReplies: 8Last Post: 01-27-2011, 09:51 AM -
Sorting
By Freakzoyd in forum New To JavaReplies: 3Last Post: 01-21-2011, 02:02 AM -
little help with sorting
By drgnfire25 in forum New To JavaReplies: 3Last Post: 01-15-2011, 09:23 PM -
Help in sorting
By nn12 in forum New To JavaReplies: 3Last Post: 01-08-2011, 06:15 PM -
sorting
By jot321 in forum New To JavaReplies: 18Last Post: 10-02-2008, 10:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks