Javascript 倒转句子中的单词,但不要倒转字母

Javascript 倒转句子中的单词,但不要倒转字母,javascript,java,netbeans,Javascript,Java,Netbeans,我想制作一个程序,只反转单词,而不是字母 例如 i love india google is the best website 。。。应该成为 india love i website best the is google 另一个例子 i love india google is the best website 。。。应该成为 india love i website best the is google 我对空格进行了彻底的研究,但什么也没发现。 我的逻辑是,我应该给

我想制作一个程序,只反转单词,而不是字母

例如

i love india
 google is the best website
。。。应该成为

india love i
 website best the is google
另一个例子

i love india
 google is the best website
。。。应该成为

india love i
 website best the is google
我对空格进行了彻底的研究,但什么也没发现。
我的逻辑是,我应该给你我的程序,这是不工作。如果您在我的代码中发现一个小错误,请给出解决方案和我的程序的更正副本。另外,如果你不太忙,你能给我一个流程图中的逻辑吗

谢谢您抽出时间。

1。 将每行的单词存储在字符串数组中。 2.
将数组元素从最后一项打印到第一项。

您尝试过的代码在哪里?这不是我的代码site@user7294900正如你在答案中所看到的:事实上是这样,因为不管问题有多糟糕,还是有人想要提高声誉。(是的,这是一件坏事:(……)给你答案
class Solution {
     public String reverseWords(String s) {
        if (s == null || s.length() == 0) {
            return "";
         }

    // split to words by space
    String[] arr = s.split(" ");
    StringBuilder sb = new StringBuilder();
    for (int i = arr.length - 1; i >= 0; --i) {
        if (!arr[i].equals("")) {
            sb.append(arr[i]).append(" ");
        }
    }
    return sb.length() == 0 ? "" : sb.substring(0, sb.length() - 1);
  }
}