I am suppose to use methods in order to count number of words in the a sentence. I wrote this code and I am not quite sure why it doesn\'t work. No matter what I write, I on
i<=str.length()-1 should probably be i or you will get an IndexOutOfBoundsException at str.charAt(i+1) (the available values are str.charAt(0) to str.charAt(str.length()-1)).