java - Determining if a given string of words has words greater than 5 letters long -


so, i'm in need of on homework assignment. here's question:

write static method, getbigwords, gets string parameter and returns array whose elements are words in parameter that contain more 5 letters. (a word defined contiguous sequence of letters.) so, given a string "there 87,000,000 people in canada", getbigwords return array of 2 elements, "people" , "canada".

what have far:

public static getbigwords(string sentence) {   string[] = new string;   string[] split = sentence.split("\\s");   for(int = 0; < split.length; i++)   {     if(split[i].length => 5)     {       a.add(split[i]);     }   }   return a; } 

i don't want answer, means guide me in right direction. i'm novice @ programming, it's difficult me figure out i'm doing wrong.

edit:

i've modified method to:

public static string[] getbigwords(string sentence) {     arraylist<string> result = new arraylist<string>();     string[] split = sentence.split("\\s+");     for(int = 0; < split.length; i++)     {         if(split[i].length() > 5)         {             if(split[i].matches("[a-za-z]+"))             {                 result.add(split[i]);             }         }     }     return result.toarray(new string[0]); } 

it prints out results want, online software use turn in assignment, still says i'm doing wrong. more specifically, states:

edith de stance states: ⇒     you might want use: += ⇒     you might want use: == ⇒     you might want use: + 

not sure means....

the main problem can't have array makes bigger add elements.

you have 2 options:

  • arraylist (basically variable-length array).

  • make array guaranteed bigger.

also, notes:

the definition of array needs like:

int size = ...;      //  v- note square brackets here string[] = new string[size]; 

arrays don't have add method, need keep track of index yourself.

you're splitting on spaces, 87,000,000 match. validate string manually ensure consists of letters.

it's >=, not =>.

i believe function needs return array:

public static string[] getbigwords(string sentence) 

it needs return something:

return result.toarray(new string[0]); 

rather than

return null; 

the "you might want use" suggestions points might have process array character character.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -