I wanted to make a word count, but exclude all of the words that started with a number.
The code below is supposed to print the number 4, but it instead prints 5.
public class WordCountLab {
public static void main(String[] args) {
String Words = "This is a test123 123";
int WordCount = 1;
for (int i = 0; i < Words.length(); i++)
{
if (Words.charAt(i) == ' ')
{
WordCount++;
if (Character.isDigit(Words.charAt(i)))
{
WordCount++;
}
}
}
System.out.println("The number of words is " + WordCount);
}
}