Results 1 to 3 of 3
Thread: Damn java - got me again.
- 07-11-2008, 01:19 AM #1
Member
- Join Date
- Jun 2008
- Posts
- 20
- Rep Power
- 0
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:
I am getting the following errors: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; }
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.
- 07-11-2008, 02:11 AM #2
Or, possibly better now that I read your specs \S == pretty much anything except what you split the string on.Java Code:// at least n times \w{5,}?Last edited by Nicholas Jordan; 07-11-2008 at 02:14 AM.
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 07-11-2008, 06:10 AM #3
Member
- Join Date
- Jun 2008
- Posts
- 20
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks