题解 | #句子逆序#

句子逆序

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

傻瓜题

import java.util.Scanner;

public class HJ13 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in=new Scanner(System.in);
        String str=in.nextLine();
        String s[]=str.split(" ");
        for(int i=s.length-1;i>=0;i--)
            if(i!=0)
                System.out.print(s[i]+" ");
            else
                System.out.print(s[i]);
    }

}
全部评论
import java.io.IOException; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(System.in); String str = scanner.nextLine(); String[] strArray = str.split(" "); List<string> list = Arrays.asList(strArray); Collections.reverse(list); for(String strs:list){ System.out.print(strs+" "); } } } 我藐视复杂了</string>
1 回复 分享
发布于 2022-07-23 18:46
这样子最后会多一个空格吧
点赞 回复 分享
发布于 2022-07-03 18:17
你这叫逆序打印把,好像不叫逆序句子把。奇淫巧技
点赞 回复 分享
发布于 2022-04-22 19:30

相关推荐

不愿透露姓名的神秘牛友
07-04 18:25
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 11:35
程序员小白条:话太多,没实力和学历,差不多回答回答就行了,身份地位不一样
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
49
12
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务