I need help with getting the number of strings whose length is >= to a minlength given by the user. ex: the string input "this is a game" minlength = 2. the length of 3 words in that sentence is >= to minLength so the output should be 3. Since 3 words are >= the minLength
I facing a problem with the output. I inputing a string, splitting it apart into individual words and sending them to method which compute the output.. The desired for the above example is 3 but i m getting 1,1,1.
public class WordCount {
/**
* @param args
*/
public static String input;
public static int minLength;
public static void Input() {
System.out.println("Enter String: ");
input = IO.readString();
System.out.println("Enter minimum word length: ");
minLength = IO.readInt();
}
public static void Calc() {
Input();
String[] words = input.split(" ");
for (String word : words) {
LetterCount(word);
}
}
public static int LetterCount(String s) {
int countWords = 0;
if (s.length() >= minLength) {
countWords += 1;
IO.outputIntAnswer(countWords);
}
return countWords;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Calc();
}
}