import java.util.Scanner; /** * */ /** * @author Harry * */ public class IsPrim { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.print("请输入所给数字:"); Scanner scanner = new Scanner(System.in); int num = scanner.nextInt(); //System.out.println(isPrim(num)); //IsPrim test = new IsPrim(); System.out.print(isPrim(num)); } private static boolean isPrim(int num){ if(num <1) return false ; if(num == 2) return true ; int i ; for(i = 2;i < num-1;i++){ if(num%i == 0){ System.out.print("并不是质数"); return false; } } System.out.print("是质数"); return true; } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-17 09:00:47