问题描述:

  将一句话的单词进行倒置,标点不倒置。比如 I like beijing. 经过函数后变为:beijing. like I 

Demo1:

import java.util.Scanner;

public class Solution {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	String input = sc.nextLine();
    	String[] s1 = input.split(" ");
    	StringBuffer s2 = new StringBuffer();
    	for(int i=s1.length-1;i>=0;i--){
    		s2.append(s1[i]+" ");
    	}
    	System.out.println(s2.toString());
    }
}

 运行结果:

I like beijing.
beijing. like I

posted on 2017-09-09 19:46  牧羊人的世界  阅读(153)  评论(0编辑  收藏  举报