题解 | #句子逆序#

句子逆序

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

相关推荐

09-12 18:28
门头沟学院 Java
网友描述的太精准了👍
迷茫的大四🐶:不管活脏还是累,钱到位就行,钱到位啥都不用抱怨
投递字节跳动等公司10个岗位
点赞 评论 收藏
分享
迷茫的大四🐶:哇靠,哥们,啥认证啊,副总裁实习,这么有实力嘛
一起聊美团
点赞 评论 收藏
分享
评论
53
12
分享

创作者周榜

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