class prime{
private int num
static boolean isprime(int num){
if(num<=1) return false
int i
for(i=2i<=num/2i++)
if(num%i==0) return false
return true
}
}
class Main {
public static void main (String[] args)
throws IOException{
int num=0
String data
BufferedReader br = new
BufferedReader(new
InputStreamReader(System.in))
System.out.print( "请输入一个整数:" )
data=br.readLine ()
try{
num = Integer.parseInt (data)
}
catch(NumberFormatException e){}
if(prime.isprime (num)){
System.out.println ( num+"是素数!" )
}
else
System.out.println ( num+"不是素数!" )
}
}
祝君好运啊
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)