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); }