打印1-100之内的20个随机数大集合中的偶数

打印1-100之内的20个随机数大集合中的偶数

package cn.itcast.day04.demo03;

import java.util.ArrayList;
import java.util.Random;

/**
 * @author ChenDan
 * @date 2019/7/9 13:19
 */
public class Demo01SelectArray {
    public static void main(String[] args) {
        ArrayList big = new ArrayList<>();
        Random r = new Random();
        for (int i = 0; i < 20; i++) {
            int num = r.nextInt(100) + 1;
            big.add(num);
        }

        ArrayList small = getSmall(big);
        System.out.println(small.size());
        for (int i = 0; i < small.size(); i++) {
            System.out.println(small.get(i));
        }

    }

    public static ArrayList getSmall(ArrayList big) {
        ArrayList small = new ArrayList<>();

        for (int i = 0; i < big.size(); i++) {
            int num = big.get(i);
            if (num % 2 == 0) {
                small.add(num);
            }
        }
        return small;
    }

}

你可能感兴趣的:(打印1-100之内的20个随机数大集合中的偶数)