Write a program that takes a string containing a sentence or a set of sentences, and counts the number of words in the sentence that meet or exceed a specified minimum length (in letters). For example, if the minimum length entered is 4, your program should only count words that are at least 4 letters long.
Input the string and the minimum word length (integer), in that order, and output the word count (integer). Words will be separated by one or more spaces. Non-letter characters (spaces, punctuation, digits, etc.) may be present, but should not count towards the length of words.
problem!! Non-letter characters (spaces, punctuation, digits, etc.) may be present, but should not count towards the length of words.
Im addressing every number and punctuation, is der another way to not count the numbers and punctuations?
Input the string and the minimum word length (integer), in that order, and output the word count (integer). Words will be separated by one or more spaces. Non-letter characters (spaces, punctuation, digits, etc.) may be present, but should not count towards the length of words.
public class WordCount {
public static void main(String[] args) {
IO.outputStringAnswer("Enter a sentence");
String str = IO.readString();
IO.outputStringAnswer("Enter a min number in length");
int len = IO.readInt();
int count = 0;
String[] a;
a = str.split(" ");
int b = a.length;
for (int i = 0; i < b; i++) {
if (a[i].contains(",")||a[i].contains(".")||a[i].contains("1")||a[i].contains("!")||a[i].contains("2")||a[i].contains("3")||a[i].contains("4")) {
a[i] = a[i].replace("," , " ");
a[i] = a[i].replace("." , " ");
a[i] = a[i].replace("1" , " ");
a[i] = a[i].replace("!" , " ");
a[i] = a[i].replace("2" , " ");
a[i] = a[i].replace("3" , " ");
a[i] = a[i].replace("4" , " ");
}
if (a[i].trim().length() >= len) {
count++;
}
}
IO.outputIntAnswer(count);
}
}
problem!! Non-letter characters (spaces, punctuation, digits, etc.) may be present, but should not count towards the length of words.
Im addressing every number and punctuation, is der another way to not count the numbers and punctuations?