I'm trying to count words in an array. But it doesn't work.

My code:

```
public static int countWords(String input)
{
    char []a = input.toCharArray();
    int spaces = 0;
    for(int i = 0; i < a.length; i++)
        if(a[i] == ' ')
            spaces++;
    return spaces + 1;  
}

```

What is the problem?

My input was `"stack over flow"`.