You are viewing a single comment's thread. Return to all comments →
From my HackerRank solutions.
import static java.lang.System.in; class Prime { void checkPrime(int... numbers) { for (int num : numbers) { if (isPrime(num)) { System.out.print(num + " "); } } System.out.println(); } boolean isPrime(int n) { if (n < 2) { return false; } else if (n == 2) { return true; } else if (n % 2 == 0) { return false; } int sqrt = (int) Math.sqrt(n); for (int i = 3; i <= sqrt; i += 2) { if (n % i == 0) { return false; } } return true; } }
Let me know if you have any questions.
Prime Checker
You are viewing a single comment's thread. Return to all comments →
Java solution - passes 100% of test cases
From my HackerRank solutions.
Let me know if you have any questions.