题解 | #简单密码#

简单密码

https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] split = s.split("");
        for (int i = 0; i < split.length; i++) {
            char c = split[i].charAt(0);
            if (split[i].matches("[abc]")){
                s = s.replace(c, '2');
            }else if (split[i].matches("[def]")){
                s = s.replace(c,'3' );
            }else if (split[i].matches("[ghi]")){
                s = s.replace(c,'4' );
            }else if (split[i].matches("[jkl]")){
                s = s.replace(c,'5' );
            }else if (split[i].matches("[mno]")){
                s = s.replace(c,'6' );
            }else if (split[i].matches("[pqrs]")){
                s = s.replace(c,'7' );
            }else if (split[i].matches("[tuv]")){
                s = s.replace(c,'8' );
            }else if (split[i].matches("[wxyz]")){
                s = s.replace(c,'9' );
            }
        }
        String lowerCase = s.toLowerCase();
        String[] split1 = lowerCase.split("");
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < split1.length; i++) {
            if (split1[i].matches("[z]")){
               split1[i]="a";
            } else if (split1[i].matches("[a-y]")){
                char c = split1[i].charAt(0);
                Integer in = Integer.valueOf(c);
                Integer in1 = in+1;
                int i1 = in1.intValue();
                char i11 = (char) i1;
                split1[i]=i11+"";
            }
            sb = sb.append(split1[i]);
        }
        String code = sb.toString();
        System.out.println(code);
    }
}

全部评论

相关推荐

身边有人上海、深圳&nbsp;6、7k&nbsp;都去了,真就带薪上班了。
程序员小白条:木的办法, 以后越来越差,还是家附近宅着吧,毕业的人越来越多,岗位都提供不出来,经济又过了人口红利期
点赞 评论 收藏
分享
码农索隆:想看offer细节
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-04 18:25
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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