Java examples for java.lang:int prime
previous Prime
public class Main{ public static long previousPrime(long input) { long lastFound = input; if (input == 2) return -1; else/*from w w w.j a va 2 s.c o m*/ lastFound -= 2; while (!PrimeUtil.isPrime(lastFound)) { lastFound -= 2; } return lastFound; } public static boolean isPrime(long num) { if (num < 2) { return false; } else if (num == 2) { return true; } else if (num % 2 == 0) { return false; } else { for (int divisor = 3; divisor <= Math.sqrt(num); divisor += 2) { if (num % divisor == 0) { return false; } } return true; } } }