用java实现一个简单的字符串逆序
例如:输入"hello world"
输出:"world hello"

解决方案 »

  1.   

    StringBuffer有个reverse方法,直接转就可以了
      

  2.   

    的确有,但是是所有字符都逆序!!!
    而不能达到 “world hello” 的效果
      

  3.   

    split
    再从后遍历,组合起来.
      

  4.   

    楼上的各位说的很正确,我替你们把代码写下来。public class Test { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub String str = "Hello World This is just a test";

    String[] temp = str.split(" ");

    String[] newStrings = new String[temp.length];

    for (int i = 0; i < temp.length; i++) {
    newStrings[i] = temp[temp.length - i - 1];
    }

    for (int i = 0; i < newStrings.length; i++) {
    System.out.print(newStrings[i] + " ");
    }

    }}输出:
    test a just is This World Hello