How do I count the number of words in a string?

后端 未结 8 1666
感情败类
感情败类 2021-01-13 02:54

I need to count the number of words and I am assuming the correct way to do it is by calculating the number of times that the previous character in a string is not a letter

8条回答
  •  我在风中等你
    2021-01-13 03:35

       if (string.charAt(i-1) == alphabets.charAt(j)) {
           counter++;
       }
    

    You are incrementing the counter if the character is some alphabet character. You should increment it if it is no alphabet character.

提交回复
热议问题