题解 | #牛牛的素数判断#

牛牛的素数判断

http://www.nowcoder.com/practice/81c8387f72824cceb5c955e3dbfd2882

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();
        int[] nums = new int[count];
        for(int index = 0; index < count; index++){
            nums[index] = scanner.nextInt();
        }
        for(int index = 0; index < count; index++){
            if(check(nums[index])){
                System.out.println("true");
            }else{
                System.out.println("false");
            }
        }
    }
    
    private static boolean check(int num){
        if (num < 2) {
            return false;
        }
        for (int index = 2; index <= num / index; index++ )
        {
            if (num % index == 0) {
                return false;
            }
        }
        return true;
    }
}

全部评论

相关推荐

05-14 20:34
门头沟学院 Java
窝补药贝八股:管他们,乱说,反正又不去,直接说680
点赞 评论 收藏
分享
06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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