You are viewing a single comment's thread. Return to all comments →
Java 7 solution:
import static java.lang.System.in; class Prime { public void checkPrime(int... args) { for (int arg : args) { if (isPrime(arg)) { System.out.print(arg + " "); } } System.out.println(); } private boolean isPrime(int num) { if (num == 1) { return false; } int maxDivisor = (int) Math.sqrt(num); for (int i = 2; i <= maxDivisor; i++) { if (num % i == 0) { return false; } } return true; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Prime Checker
You are viewing a single comment's thread. Return to all comments →
Java 7 solution: