首页 > 代码库 > java - day07 - PrimeNum

java - day07 - PrimeNum

判断质数

 1 package day06;
 2 import java.util.Scanner;
 3 
 4 //验证质数
 5 public class primeNum {
 6     public static void main(String[] args){
 7         Scanner scan = new Scanner(System.in);
 8         
 9         int num = scan.nextInt();
10         int counter = 0;
11         
12         //算质数可能
13         for(int i=2;i<num;i++){
14             if(num%i == 0){
15                 counter++;
16             }
17         }
18         
19         //判断
20         if(counter>0){
21             System.out.println("输入值\t"+num+"\t不是质数");            
22         }else{
23             System.out.println("输入值\t"+num+"\t是质数");                        
24         }
25         scan.close();
26     }
27 }

 

java - day07 - PrimeNum