0

a method program to check whether a number is prime or not.

6th Sep 2016, 12:39 PM
Simrah Mahmood
2 Respuestas
+ 1
public static boolean isPrime(int n) { if (n < 2) { return false; } for (int i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) { return false; } } return true; }
6th Sep 2016, 2:06 PM
Zen
Zen - avatar
- 1
u can use it isProbablePrime () method if BigInteger class.
6th Sep 2016, 12:42 PM
Sonu Mishra
Sonu Mishra - avatar