java实现简答数字解密

public static void main(String[] args) {
   
    // 1.将数据反转
    // 将数据存储到数组中
    // 计算整数的长度
    Scanner sc = new Scanner(System.in);
    System.out.print("请输入你要解密的数字:");
    int unencrytionDate = sc.nextInt();
    //定义变量记录初始化的数字
    int unencrytionDate1 = unencrytionDate;
    // 定义变量记录整数的长度
    int count = 0;
    // 定义变量接收最终结果
    int resultNum = 0;
    while (unencrytionDate != 0) {
        unencrytionDate = unencrytionDate / 10;
        count++;
    }

    System.out.println("整数的长度是:" + count);
    // 数组初始化
    int[] testNum = new int[count];
    // 索引初始化
    int index = 0;
    // 将整数存数组中去
    while (unencrytionDate1 != 0) {
        // 将整数反转
        int geNum = unencrytionDate1 % 10;
        unencrytionDate1 = unencrytionDate1 / 10;
        testNum[index] = geNum;
        index++;

    }
    for (int i = 0; i < testNum.length; i++) {
        // 由于加密是通过对10取余的方式进行获取的
        // 所以在解密的时候就需要判断,0-4之间+10  5-9数字不变
        if (testNum[i] >= 0 && testNum[i] <= 4){
            testNum[i] += 10;
        }

        // 将数据减5
        testNum[i] -= 5;
       // 进行结果数字拼接
        resultNum = resultNum * 10 + testNum[i];

    }
    System.out.println("解密后的数字是:" + resultNum);



}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值