[算法][od][字符串]单词倒序

在这里插入图片描述
在这里插入图片描述

实现代码

    public static  void solution(){
    
    
        String s ="woh era uoy? I ma enif.";

        String [] arr = s.split(" ");

        String ans = null;
        for (String s1 : arr) {
    
    
            int len = s1.length();
            String temp ="";
            String d = null;
            for (int i=len-1;i>=0;i--){
    
    
                if (Character.isLetter(s1.charAt(i))){
    
    
                    temp+=s1.charAt(i);
                }else {
    
    
                   d=s1.charAt(i)+"";
                }
            }
            if (null != d){
    
    
                temp+=d;
            }
            if (null==ans){
    
    
                ans=temp;
            }else {
    
    
                ans=ans+" "+temp;
            }

        }

        System.out.println(ans);
    }

猜你喜欢

转载自blog.csdn.net/zhaoliubao1/article/details/139011047