首页 > 代码库 > 计算质数

计算质数

package test.com.ict.compent.amazom;import java.util.ArrayList;import java.util.List;public class MathPrime {    public static void main(String[] args) {        List<Integer> add = new MathPrime().mathPrime(100);        for (Integer integer : add) {            System.out.print(integer+",");        }    }        public List<Integer> mathPrime(int num){        List<Integer> list=new ArrayList<Integer>();                 while(true){            boolean a=false;            Integer zhishu = zhishu(num);            list.add(zhishu);            if(zhishu==num){                a=true;            }else{                num=num/zhishu;            }            if(a){                break;            }        }                return list;    }        public Integer zhishu(int num){        int a=0;        for (int i = 2; i < num; i++) {            if(num%i!=0){                continue;            }else{                a=i;                break;            }        }        if(a==0){            a=num;        }        return a;            }    }

 

计算质数