题解 | 多组_带空格的字符串_T组形式

多组_带空格的字符串_T组形式

https://www.nowcoder.com/practice/cff28a28d7f54419a640a8bb19f4275f

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc   = new Scanner(System.in);
        int t  = sc.nextInt();
        sc.nextLine();
        for(int i = 0;i<t;i++){
            int n  = sc.nextInt();
            sc.nextLine();
            String s  = sc.nextLine();
            String result  = reverseString(s);
            System.out.println(result);
        }
        sc.close();
    }
    public static String reverseString(String s){
        String nospace = s.replaceAll(" ","");
        StringBuilder sb  = new StringBuilder(nospace);
        return sb.reverse().toString();
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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