题解 | #句子逆序#

句子逆序

http://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        System.out.println(SentenceRevers(str));
    }
    
    public static String SentenceRevers(String s){
       String[] inStringArray = s.split(" ");
       StringBuilder sb = new StringBuilder();
       for(int i = inStringArray.length - 1;i >= 0;i--){
           sb.append(inStringArray[i] + " ");
       }
       return sb.toString().trim();
    }
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务