public String reverseWords(String s){
  if (s == null || s.length() == 0)   return "";
  String res="";
  for (int i=0; i < s.length(); i++) {
    char c=s.charAt(i);
    if (c == ' ')     continue;
 else {
      StringBuilder word=new StringBuilder();
      while (i < s.length()) {
        c=s.charAt(i);
        if (c == ' ')         break;
        word.append(c);
        i++;
      }
      res=res.length() == 0 ? word.toString() : word.toString() + " " + res;
      i--;
    }
  }
  return res;
}

public String reverseWords ( String s ) { if ( s == null || s . length ( ) == 0 ) return "" ; String res = "" ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( c == ' ' ) continue ; else { StringBuilder word = new StringBuilder ( ) ; while ( i < s . length ( ) ) { c = s . charAt ( i ) ; if ( c == ' ' ) break ; word . append ( c ) ; i ++ ; } res = res . length ( ) == 0 ? word . toString ( ) : word . toString ( ) + " " + res ; i -- ; } } return res ; }
if space , continue if not , get the word and insert to the front of result note that result may not contain spaces before or after
