输入the slay is blue,输出blue is slay the
代码片
.
public static void main(String[] args) {
String str="the slay is blue";
String reverse = reverse(str);
System.out.println(reverse);
}
private static String reverse(String str) {
StringBuffer sbf = new StringBuffer();
if (str != null) {
String[] arr = str.split(" ");
for (int i = arr.length - 1; i >= 0; i--) {
sbf.append(arr[i]+" ");
}
}
return sbf.toString().trim();
}