Results 1 to 3 of 3
  1. #1
    frasifrasi is offline Member
    Join Date
    Jun 2008
    Posts
    20
    Rep Power
    0

    Default Damn java - got me again.

    This problem asks us to return all words in a string(which can contain weird crap like numbers and symbols) that are longer than five letters in a new array.

    Here is what I have so far:

    Java Code:
    public static String[] getBigWords(String sentence){  
      
             //sentence = sentence.replaceAll("\\d","");
            
             String [] temp = null;
             temp = sentence.split(" ");
           
             int size = 0;
             int k =0;
             for(int i = 0; i < temp.length; i++) {
              if(temp[i].length() > 5)
                size++;
             }
             
            String[] big = new String[size];
              for(int i = 0; i < temp.length; i++) {
              if(temp[i].length() > 5){
                big[k] = temp[i].toString(); 
                k++;}
               }
     return big;        
     }
    I am getting the following errors:

    Problems Detected:
    *****⇒*****Word '67000120909' incorrrectly returned in result
    *****⇒*****Word '6A7B0C0V0D1E2S0D9D09' incorrrectly returned in result
    *****⇒*****Word 'location' not returned in result
    *****⇒*****Word 'son-in-law' incorrrectly returned in result

    Fails When:
    *****⇒*****Long non letter strings
    *****⇒*****Punctuation
    *****⇒*****Punctuation, duplicate words, beginning/middle/end

    --> Is there a regex expression that has everything but characters in it so I can place it in my replace function?

    Thanks.

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Java Code:
    // at least n times
    \w{5,}?
    Or, possibly better now that I read your specs \S == pretty much anything except what you split the string on.
    Last edited by Nicholas Jordan; 07-11-2008 at 03:14 AM.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    frasifrasi is offline Member
    Join Date
    Jun 2008
    Posts
    20
    Rep Power
    0

Posting Permissions

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