import java.util.*; public class reverse { public static StringBuffer start(String data) { StringBuffer ans = new StringBuffer(); // Split the input string by space String[] words = data.split(" "); // Iterate through the words in reverse order and append them to the answer for (int i = words.length - 1; i >= 0; i--) { ans.append(words[i]); if(i != 0){ ans.append(" "); } } return ans; } public static void main(String[] args) { String data = "ot eb ro ton ot eb"; System.out.println(start(data)); } } [2024-10-09 17:16:06 | AI写代码神器 | 443点数解答]