public class Test2 {
public static void main(String[] args){
String str1 ="the sky is blue";
String str2 =" hello world! ";
String str3 ="a good example";
System.out.println(getBackStr(str1));
System.out.println(getBackStr(str2));
System.out.println(getBackStr(str3));
}
public static String getBackStr(String s){
String[] str = s.split(" ");
int length = str.length;
int cycCount = length /2+length %2;
for (int i =0; i < cycCount; i++) {
String temp = str[i];
str[i] = str[length-1-i];
str[length-1-i] = temp;
}
StringBuffer sb =new StringBuffer();
for(int i =0 ; i < str.length ; i++){
if(str[i].equals("")){
continue;
}
sb.append(str[i]).append(" ");
}
if(sb.length() !=0)
return sb.substring(0,sb.length()-1);
return "";
}
}