句子反转 I am a Chinese Hello Word!反转为Word! Hello Chinese a am I

package demo1;

public class MyClass1
{
    public static String Reserver(String str){
        String [] myStr=str.split(" ");
        StringBuffer newStr=new StringBuffer();
        for(int i=myStr.length-1;i>=0;i--){
            newStr.append(myStr[i]+" ");
        }
        return newStr.toString();
    }
    public static void main(String []args){
        String str="I am a Chinese Hello Word!";
        System.out.println(Reserver(str));
    }
}



输出:Word! Hello Chinese a am I 

 

©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页