题解 | #简单密码#

简单密码

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


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        String p = newPassword(str);
        System.out.println(p.toString());
    }
    
    static String newPassword(String password){
        char[] ch = password.toCharArray();
        for(int i = 0; i < ch.length;i++){
            if(ch[i] >= 'A' && ch[i] < 'Z'){
                ch[i] += 33;
            }else if(ch[i] == 'Z'){
                ch[i] = 'a';
            }else if(ch[i] >= 'a' && ch[i] <= 'c' || ch[i] == '2'){
                ch[i] = '2';
            }else if(ch[i] >= 'd' && ch[i] <= 'f' || ch[i] == '3'){
                ch[i] = '3';
            }else if(ch[i] >= 'g' && ch[i] <= 'i' || ch[i] == '4'){
                ch[i] = '4';
            }else if(ch[i] >= 'j' && ch[i] <= 'l' || ch[i] == '5'){
                ch[i] = '5';
            }else if(ch[i] >= 'm' && ch[i] <= 'o' || ch[i] == '6'){
                ch[i] = '6';
            }else if(ch[i] >= 'p' && ch[i] <= 's' || ch[i] == '7'){
                ch[i] = '7';
            }else if(ch[i] >= 't' && ch[i] <= 'v' || ch[i] == '8'){
                ch[i] = '8';
            }else if(ch[i] >= 'w' && ch[i] <= 'z' || ch[i] == '9'){
                ch[i] = '9';
            }else if(ch[i] == '1'){
                ch[i] = '1';
            }else if(ch[i] == '0'){
                ch[i] = '0';
            }
        }
        return String.valueOf(ch);
    }
}
全部评论

相关推荐

喜欢走神的孤勇者练习时长两年半:爱华,信华,等华,黑华
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务