Write a static method, getBigWords, that gets a String parameter and returns an array whose elements are the words in the parameter that contain more than 5 letters. (A word is defined as a contiguous sequence of letters.) So, given a String like "There are 87,000,000 people in Canada", getBigWords would return an array of two elements, "people" and "Canada".
Now, the only thing I could think of doing was this:
public static String[] getBigWords ( String t)
{
String[] end=t.split(" ");
int co= 0;
for (int o=0; o<end.length; o=o+1)
{
if(end[o].length()>5)
{
co=co+1;
}
}
String[] y=new String[co];
int g=0;
for (int o=0; o<end.length; o=o+1)
{
if(end[o].length()>5)
{
y[g]=end[o];
g=g+1;
}
}
return y;
}
The problem is that this includes strings with numbers in them, and hyphened words, and also words with punctuation at the end. (For example 100000000 is included bu shouldn't be. Same with 09JBAS2371N, and son-in-law. Also, the last word of the sentence is included with the period, when it should be included without the punctuation, and only if it is more than five letters long without counting the punctuation.)
So what I'm trying to figure out it, how to split the words at all punctuation types in addition to whitespace, and how to not include strings that include digits as words.
Anyone have any ideas?

New Topic/Question
Reply




MultiQuote



|