码迷,mamicode.com
首页 > 编程语言 > 详细

【Java】质数判断

时间:2020-01-22 20:03:36      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:ati   div   bool   stat   static   isp   lse   false   OLE   

    static boolean isPrime(int n) {
        if(n<=1) {
            return false;
        }
        if(n==2||n==3) {
            return true;
        }
        if(n%6!=1&&n%6!=5) {
            return false;
        }
        for(int i=2;i<=(int)Math.sqrt(n);i++) {
            if(n%i==0) {
                return false;
            }
        }
        return true;
    }

【Java】质数判断

标签:ati   div   bool   stat   static   isp   lse   false   OLE   

原文地址:https://www.cnblogs.com/LPworld/p/12229158.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!