} else if ((inputString.charAt(i + 1) == ' ' || (inputString.charAt(i + 1) == last) {
This line is missing a closing parentheses. That's the only issue I had compiling, as fixing this issue allowed the rest of the code to compile.
Edit: There are some issues I ran into when running your code though. Namely an out of bounds exception being thrown when I tested a simple string like "hello"
I did some debugging, and looking at your method again, I offer these tips to you:
1- start a counter at 0, and have a boolean variable to keep track of whether you hit a space or not for this particular method of counting a word
(probably easier to use substring, but I was able to see what you were trying to do)
2- I was confused by your loop logic. This is what I got to work:
for 0 to length of the string
{
if the char at this location is not a space:
{
if the flag indicates this is a new word
{
increment count
set the flag to false
}
}else (the char is a space)
set the flag to true
}end for loop
Let's test this on the string "hello"
Starting at the beginning, we see that char 0 is h thus not a space. And since our flag is true, this is a new word, so we increment our counter. Then we set our flag to false.
Move to char 1 is e, which is not a space, but our flag says this is not a new word, so nothing happens
Move to char 2 is l, which is not a space, but again, the flag indicates we are not at a new word. Nothing happens again.
This will continue for the other l, and the o. Our count remains at 1, which is what we expect. To see if it works on other strings test out the others you posted: wordCount("how are you?") should return 3
wordCount(" this string has wide spaces ") should return 5
wordCount(" ") should return 0
This was my method, but there are other ways of getting a word count. This one uses some ideas already present in your code so you may want to try it 1st. Good luck.