题解 | #简单密码#--分支加密

简单密码

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String str = in.nextLine();
            // 加密
            char[] chars = str.toCharArray();
            for (char ich : chars) {
                encode(ich);
            }
        }
    }
    
    private static void encode(char ich) {
        // 小写字母比大写字母大32
        if (ich >= 'A' && ich <= 'Y') {
            System.out.print((char) (ich + 33));
        } else if (ich == 'Z') {
            System.out.print('a');
        } else if (ich >= 'a' && ich <= 'c') {
            System.out.print('2');
        }  else if (ich >= 'd' && ich <= 'f') {
            System.out.print('3');
        }  else if (ich >= 'g' && ich <= 'i') {
            System.out.print('4');
        }  else if (ich >= 'j' && ich <= 'l') {
            System.out.print('5');
        }  else if (ich >= 'm' && ich <= 'o') {
            System.out.print('6');
        }  else if (ich >= 'p' && ich <= 's') {
            System.out.print('7');
        }  else if (ich >= 't' && ich <= 'v') {
            System.out.print('8');
        }  else if (ich >= 'w' && ich <= 'z') {
            System.out.print('9');
        } else {
            System.out.print(ich);
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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