Once you make that change, you'll notice that your logic is not quite correct. As a suggestion without simply telling you how to fix it, note that naming variables with "temp" is rarely informative. Since every variable can be changed (unless it's final), they're all pretty much temporary.
While scanning the String, at any point you have the maximum number of spaces found previously and the number of spaces found in the current run of spaces. Write down before coding what you should do when you find a space and when you find a non-space. Also, before you start scanning you know that the current maximum is zero, but what happens when you finish scanning?
Finally, you'll want to try multiple test Strings, taking extra care to come up with "corner cases": inputs that may trigger special cases in your logic. One obvious special case is a String with no spaces. Can you think of others?