import java.util.Scanner;
public class bye{
public static void main (String[] args){
boolean isPrime = true;
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a positive integer:");
int num = sc.nextInt();
if (num > 0){
for (int i = 2; i <= num/2; i++){
if (num % i == 0){
isPrime = false;//is not a prime
break;
}
}
if (isPrime == true){
System.out.println(num + " is a prime");
}
else{
System.out.println(num + " is not a prime");
}
}
else{
System.out.println("Error!!!");
}
}
}
java 判断素数
最新推荐文章于 2024-09-10 10:21:38 发布