首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

多人围一圈报数有关问题

2012-09-10 
多人围一圈报数问题public static void str() {ListInteger list new ArrayListInteger()ListInte

多人围一圈报数问题
    public static void str() {
        List<Integer> list = new ArrayList<Integer>();
        List<Integer> list1 = new ArrayList<Integer>();
        for (int i = 0; i < 9; i++) {
            list.add(i + 1);
        }

        int k = 0;
        long time = System.currentTimeMillis();
        while (list.size() > 0) {
            for (Integer j : list) {
                k++;
                if (k % 3 == 0) {
                    System.out.print(j + " ");
                    list1.add(j);
                }
            }
            list.removeAll(list1);
            list1.clear();
        }
        System.out.println("耗时:" + (System.currentTimeMillis() - time));
    }

热点排行