I, personally, think it would be easier to tokenize the
String and toUpperCase the first char of each token. Then pop the tokens back into the StringBuffer.
Right now, I think you'll have additional problems with if you're ending the String with a space. You might be better off using "continue" instead of doing the work in lines 14-20.
Also,
you should probably use StringBuilder, not StringBuffer.