关于#java#的问题,请各位专家解答!(开发工具-eclipse)

创建一个方法test1,返回值是数组,参数数组
去除数组中的质数,返回新数组

package com.yelang.exifinfo;

import java.util.ArrayList;

public class Cfb {

    public static boolean isPrime(int num) {
        /*
         * 质数定义:只有1和它本身两个因数的自然数
         *
         * 1. 小于等于1或者是大于2的偶数,直接返回false
         * 2. 2直接返回true
         * 3. 从3开始算起(每次加2,截止为输入值的平方根),每次输入值除以前者,若出现一个能除尽则直接返回false
         * 4. 全都除不尽,则为质数,返回true
         * */
        if (num <= 1 || num > 2 && num % 2 == 0) {
            return false;
        } else if (num == 2) {
            return true;
        }
        for (int i = 3; i <= Math.sqrt(num); i += 2) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
    
    public static Integer[] FilterPrime(Integer [] args) {
        Integer [] result = new Integer [] {};
        ArrayList<Integer> list = new ArrayList<Integer>();
        for(int num : args) {
            if(!Cfb.isPrime(num)) {
                list.add(num);
            }
        }
        return list.toArray(result);
    }

    public static void main(String[] args) {
        Integer [] argArray = Cfb.FilterPrime(new Integer[] {2,4,6,8,5,12});
        for(Integer arg : argArray) {
            System.out.println(arg);
        }
    }
}

希望可以解决你的疑问