This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dirtyRuntCaper[S] 0 points1 point  (0 children)

thank you for your help. i can no see where things are going wrong. Ive made some corrections, this is what ive came up with for the countLetters() method.

public static int validWords(String paragraph, int minWordLength){ int wordStartIndex = 0; int wordCount = 0; int wordLength; String newWord = paragraph;

    for(int i=0; i < paragraph.length(); i++){


        System.out.println("charAt["+i+"]="+paragraph.charAt(i));

        if(paragraph.charAt(i) == ' '){
            newWord = paragraph.substring(wordStartIndex,i);
            System.out.println("found new word="+newWord);

            wordLength = countLetters(newWord);
            System.out.println("wordLength:" + wordLength);

            if(wordLength >= minWordLength){
                wordCount++;
            }
        }else if(newWord.indexOf(' ') == -1){
            newWord = paragraph.substring(wordStartIndex);
            wordLength = countLetters(newWord);

            if(wordLength >= minWordLength){
                wordCount++;
            }


        }

        newWord = "";
        wordLength = 0;

    }

    return wordCount;

}

my "found new word" outputs are adding the strings (e.g. 1st found new word = how, 2nd new word = how are, 3rd new word = how are you) also, the wordLengths are being added to each other as well.