题解 | #简单密码#

简单密码

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

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        while (in.hasNext()) { 

            String a = in.next();

            System.out.println(getPasswd(a));

        }

    }

    private static StringBuilder getPasswd(String str){

        StringBuilder sb = new StringBuilder();

        for(int i=0;i<str.length();i++){

            char c = str.charAt(i);

            if(Character.isUpperCase(c)){

                if(c=='Z'){

                    sb.append('a');

                }else{

                    sb.append((char)(Character.toLowerCase(c)+1));

                }               

            }else if(Character.isLowerCase(c)){

                if(c=='a' || c=='b' || c=='c'){

                    sb.append(2);

                }else if(c=='d' || c=='e' || c=='f'){

                    sb.append(3);

                }else if(c=='g' || c=='h' || c=='i'){

                    sb.append(4);

                }else if(c=='j' || c=='k' || c=='l'){

                    sb.append(5);

                }else if(c=='m' || c=='n' || c=='o'){

                    sb.append(6);

                }else if(c=='p' || c=='q' || c=='r' || c=='s'){

                    sb.append(7);

                }else if(c=='t' || c=='u' || c=='v'){

                    sb.append(8);

                }else{

                    sb.append(9);

                }

            }else{

                sb.append(c);

            }

        }

        return sb;

    }

}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务