+ 2

Java

How to find no. is prime without using break

15th Jun 2019, 9:09 AM
Pawan Kumar
Pawan Kumar - avatar
2 ответов
+ 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; } }
15th Jun 2019, 10:37 AM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 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; }
15th Jun 2019, 9:24 AM
Anton Böhler
Anton Böhler - avatar