java prime
public class Prime {
public static boolean isPrime(int num) {
if (num<2)
return false;
for(int i=3;i<=Math.sqrt(num);i+=2)
if(num%i==0)
return false ;
return true ;
}
}
java prime
public class Prime {
public static boolean isPrime(int num) {
if (num<2)
return false;
for(int i=3;i<=Math.sqrt(num);i+=2)
if(num%i==0)
return false ;
return true ;
}
}
prime number program in java
// The following method returns a boolean indicating
// if the parameter is a prime number
private boolean isPrimeNaiveIter(int val) {
if(val == 0 || val == 1)
return false;
if(val == 2)
return true;
// Look for a divisor other than 1 and val
for(int div = 2; div*div <= val; div++) {
// if found return false
if(val % div==0)
return false;
}
// No divisors found => return it is a prime number
return true;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us