Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write this return statement so I don't return null?
    primarykey
    data
    text
    <p>I don't know where or how to place my return statement so I get back a linked list. The return of the linked list is in a loop. I need to have a return statement outside that however but can't get tit to work. I just keep getting the null return. Tried putting in an else statement but its not working. I feel like this is a simple solution but can't work it out. I know the return null is always read in this code, just don't know how to put it so it doesn't always return null.</p> <p>Method is taking in a string of numbers, getting letters attached to those numbers on a keypad, and putting possible combinations of those strings into a method that finds words and returns a linked list of those words.</p> <p>Just can't work out the return statement in the method.</p> <pre><code> public LinkedList bfs_search(String numberEntered) { //use a queue for all the unsearched combinations to go Queue&lt;String&gt; q = new LinkedList&lt;String&gt;(); q.add(""); String possibleWord = null; //loop through each number entered for(int i = 0; i &lt; numberEntered.length(); i++) { //get the letters on the keypad for current number String lettersOnKeypadNumber = T9keypad[numberEntered.charAt(i) - ASCII_ZERO]; int len = q.size(); //loop while there are letter sequences in the queue. Note len-- is same as len=len-1 so loop until only one item left in queue (the blank item inserted above) while(len -- &gt; 0) { String letterSequenceFromQ = q.remove(); //loop through each letter on the keypad number, add it to the letter sequence pulled from queue and search for that letter sequence as a word in the trie for(int j = 0; j &lt; lettersOnKeypadNumber.length(); j++) { possibleWord = letterSequenceFromQ + lettersOnKeypadNumber.charAt(j); //q.add(tmpStr); if(search(possibleWord) &amp;&amp; possibleWord.length() == numberEntered.length()) { //found it! return possibleWords(possibleWord); } else { //letter sequence is not a word, add it to the queue for possible word when get the next set of letters for the next keyed number q.add(possibleWord); } } } } return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload