题解 | #句子逆序#

句子逆序

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

相关推荐

05-23 20:31
已编辑
武汉大学 Java
内向的柠檬精在研究求...:注意把武大标粗标大 本地你俩不是乱杀
实习进度记录
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-03 17:37
点赞 评论 收藏
分享
评论
49
12
分享

创作者周榜

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