zoukankan      html  css  js  c++  java
  • Java经典编程题50道之四十八

    某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下: 每位数字都加上5,然后用和除以10的余数代替该数字, 再将第一位和第四位交换,第二位和第三位交换。

    public class Example48 {
        public static void main(String[] args) {
            f(2345);
        }

        public static void f(int num) {
            int[] c = new int[4];
            if (num > 999 && num < 10000) {
                c[0] = num / 1000;
                c[1] = (num / 100) % 10;
                c[2] = (num / 10) % 10;
                c[3] = num % 10;
                for (int j = 0; j < 4; j++) {
                    c[j] += 5;
                    c[j] %= 10;
                }
                for (int j = 0; j <= 1; j++) {
                    int temp = c[j];
                    c[j] = c[3 - j];
                    c[3 - j] = temp;
                }
                System.out.print("加密后的数字为:");
                for (int j = 0; j < 4; j++)
                    System.out.print(c[j]);
            } else {
                System.out.println("传输的数据有错,请重试!!!");
            }
        }
    }

  • 相关阅读:
    Java IO流 简介
    Centos8安装java部署环境
    RedisTemplate
    手把手教windows上安装linux虚拟机及环境配置
    使用Swagger2构建 RESTful API文档
    VMware 安装 Centos 7 虚拟机配置网络
    别再写满屏的 try catch 了
    isEmpty 和 isBlank 的用法区别
    SpringBoot 中必须掌握的45个注解
    数组的栈方法
  • 原文地址:https://www.cnblogs.com/qubo520/p/6980051.html
Copyright © 2011-2022 走看看