• 根据取模选择不同的列表


    public class test1122
    {
        /**
         * 根据取模选择不同的列表(保证code结尾的数字总是配置同一样的列表)
         * 请观察code与value的映射关系(规律:通过取模匹配)
         * 源需求:请保证以code结尾的号码总是匹配用一个list成员之一(列表)
         * @param args
         */
        public static void main(String[] args)
        {
            int[] code = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
            String[] list =
                   {"A:192.168.66.16,192.168.66.17,192.168.66.18",
                    "B:192.168.66.16,192.168.66.17,192.168.66.18",
                    "C:192.168.66.18,192.168.66.17,192.168.66.16",
                    "D:192.168.66.18,192.168.66.17,192.168.66.16"};
            int size = list.length;
            for (int i = 0; i < code.length; i++)
            {
                int index = code[i] % size;
                System.out.println("code="+code[i]+", size="+size+", index=" + index + ", value=" + list[index]);
            }
        }
    }

    运行结果:

    code=0, size=4, index=0, value=A:192.168.66.16,192.168.66.17,192.168.66.18
    code=1, size=4, index=1, value=B:192.168.66.16,192.168.66.17,192.168.66.18
    code=2, size=4, index=2, value=C:192.168.66.18,192.168.66.17,192.168.66.16
    code=3, size=4, index=3, value=D:192.168.66.18,192.168.66.17,192.168.66.16
    code=4, size=4, index=0, value=A:192.168.66.16,192.168.66.17,192.168.66.18
    code=5, size=4, index=1, value=B:192.168.66.16,192.168.66.17,192.168.66.18
    code=6, size=4, index=2, value=C:192.168.66.18,192.168.66.17,192.168.66.16
    code=7, size=4, index=3, value=D:192.168.66.18,192.168.66.17,192.168.66.16
    code=8, size=4, index=0, value=A:192.168.66.16,192.168.66.17,192.168.66.18
    code=9, size=4, index=1, value=B:192.168.66.16,192.168.66.17,192.168.66.18

  • 相关阅读:
    第二章 成员、变量和常量
    Roman To Integer
    Integer To Roman
    Container With Most Water
    搜狗2015前端工程师笔试题
    从网易与淘宝的font-size思考前端设计稿与工作流
    移动端web app自适应布局探索与总结
    CSS 常用代码
    利用 HTML 和 CSS 实现常见的布局
    CSS 尺寸单位
  • 原文地址:https://www.cnblogs.com/qqzy168/p/2765906.html
Copyright © 2020-2023  润新知