+ 2
Java
How to find no. is prime without using break
2 Answers
+ 10
The shortest way to find number is prime or not
private static boolean test(int num)
{
if (Math.pow(2,num-1)%num == 1 || num==1 || num==3)
{
return true;
}
else {
return false;
}
}
+ 2
public boolean isPrime(int x){
for(int i=2;i<x;i++){
if(x % i == 0){
return false;
}
}
return true;
}
or
public boolean isPrime(int x){
boolean result = true;
for(int i=2;i<x;i++){
if(x % i == 0){
result = false;
}
}
return result;
}