题解 | #判断质数#

判断质数

http://www.nowcoder.com/practice/4d2a100c2e544f56ac1ad17e9ffa107d

import java.util.Scanner;

public class Main { public static void main(String[] args) { Main main = new Main(); Scanner scan = new Scanner(System.in); int number = scan.nextInt(); System.out.println(main.isPrimeNumber(number)); }

public Boolean isPrimeNumber(int number) {

    //write your code here......
    
    //素数只能被自身和1整除所以对其取余判断是否为零
    for(int i =2;i<number;i++){
        //测试数字大于1所以从2开始遍历
        if(number%i==0){
            return false;
        }
    }return true;

}

}

全部评论
妙啊!
点赞 回复 分享
发布于 2022-06-19 20:17

相关推荐

爱刷美剧的菠萝蜜巴比...:丢给gpt,让他优化实习 切合实际 突出产出 可以不局限简历内容,,然后就背就好了
点赞 评论 收藏
分享
03-03 23:42
复旦大学 Java
tongx_:闹呢,这找不到其他人还活不活
点赞 评论 收藏
分享
评论
14
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务