#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    1
    Rep Power
    0

    java program help on sorting arrays


    My program assignment calls for an applet that checks for anagrams from the user's input and then redisplays them in the order of first anagram found, followed by the anagrams, and then continued until no more anagrams are left.

    For example an input of:
    Silent abc LISTEN Cab silent ABC go
    Results in an output of:
    Silent LISTEN silent abc Cab ABC

    Other directions were that in the public sortString, you need to first make the inputted words lower cased then in alphabetical order.

    In the public anagrams, you need to take the alphabetized lower-cased words and compare them to check if the words are anagrams and then output them in the way shown above.

    I have no idea how to go about this program and any direction/help on what code would be good to use to do those actions or just anything helpful would be greatly appreciated. The code given is as follows:


    Code:
     public class P3 extends JApplet implements ActionListener
     {
        private JTextField input;	// Input single line text field
        private JTextArea  output;	// Output multi-line text area
    
        public void init()
        {
           JLabel prompt;		// Input prompt
           Container c = getContentPane();	// FlowLayout Manager
           c.setLayout( new FlowLayout() );
           
           prompt = new JLabel("Enter your Anagrams <R>: ");
           input  = new JTextField(40);		// 40 char width input
           output = new JTextArea(10, 40);	// 10 x 40 output display
           output.setEditable(false);		// Do not type into text area
           
           c.add(prompt);  // Place components on applet ..
           
           input.addActionListener(this);	// Register listener
        }
        
        public void actionPerformed( ActionEvent e )
        {
           
           String str = input.getText();	// Read input textfield
           StringTokenizer tokens = new StringTokenizer( str );
           String [] words = new String[tokens.countTokens()];   // Array of Strings
           String sAnagram = null;	   // String of anagrams
        	
           output.append( "Sentence: " + str + "\n" );	// Display original sentence
        	
           for ( i = 0; tokens.hasMoreTokens() ; ++i )	// Place into array
        	  words[i] = tokens.nextToken();			// Parse next word
           sAnagram = anagrams( words );				// Return list of anagrams
           
           output.append("All Anagrams: " + sAnagram + "\n\n");	// Add to output text area ..
           input.setText("");   // Clear input text field
        }
        
        public String sortString(String w)
        {  
           StringBuffer sb = new StringBuffer(w);   // Hold sorted word
        }
    
        public String anagrams(String [] a)
        {  
           String [] aSortedStrg = new String[a.length];	// Array of sorted Strings in sentence
           
        }
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    18
    Rep Power
    0
    Write down step-by-step instructions of how you would do this yourself, if you had to do it instead of the computer. Then translate to Java.

    Comments on this post

    • StevenC agrees
  4. #3
  5. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    Chicago, IL
    Posts
    10,131
    Rep Power
    5058
    Originally Posted by nasch
    Write down step-by-step instructions of how you would do this yourself, if you had to do it instead of the computer. Then translate to Java.
    That's probably the best advice anyone can give with regards to problems of "I don't know where to begin"...
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    18
    Rep Power
    0
    u can use java.util.*
  8. #5
  9. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    Chicago, IL
    Posts
    10,131
    Rep Power
    5058
    Originally Posted by tttcao
    u can use java.util.*
    ...and that's probably the worst...
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}

IMN logo majestic logo threadwatch logo seochat tools logo