Results 1 to 3 of 3
  1. #1
    Acaul is offline Member
    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Default Sorting from an array

    Here is my code:

    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)];
    
    			
    			
    		}
    	}
    
    }
    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.
    Last edited by Acaul; 12-07-2012 at 11:08 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default 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?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Acaul is offline Member
    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Default 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.

Similar Threads

  1. C# Sorting
    By larry_d1990 in forum New To Java
    Replies: 8
    Last Post: 01-27-2011, 09:51 AM
  2. Sorting
    By Freakzoyd in forum New To Java
    Replies: 3
    Last Post: 01-21-2011, 02:02 AM
  3. little help with sorting
    By drgnfire25 in forum New To Java
    Replies: 3
    Last Post: 01-15-2011, 09:23 PM
  4. Help in sorting
    By nn12 in forum New To Java
    Replies: 3
    Last Post: 01-08-2011, 06:15 PM
  5. sorting
    By jot321 in forum New To Java
    Replies: 18
    Last Post: 10-02-2008, 10:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •