题解 | #简单密码#

简单密码

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s=in.next();
        char[] arr=s.toCharArray();
        int len=s.length();
        String res="";
        for(int i=0;i<len;i++){
            char ch=arr[i];
            if(ch>='a'&&ch<='z'){
                if(ch>='a'&&ch<='c')res+='2';
                else if(ch>='d'&&ch<='f')res+='3';
                else if(ch>='g'&&ch<='i')res+='4';
                else if(ch>='j'&&ch<='l')res+='5';
                else if(ch>='m'&&ch<='o')res+='6';
                else if(ch>='p'&&ch<='s')res+='7';
                else if(ch>='t'&&ch<='v')res+='8';
                else if(ch>='w'&&ch<='z')res+='9';
            }
            else if(ch>='A'&&ch<'Z'){
                char t= (char)(ch+32+1);
                res+=t;
            }
            else if(ch=='Z')res+='a';
            else res+=ch;
        }
        System.out.println(res);
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
02-16 22:33
杉川机器人 嵌入式工程师 18.0k*13.0, 年终奖1~9个月浮动
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务