Prime Checker

  • + 0 comments
    import static java.lang.System.in;
        
    class Prime{
        public void checkPrime(int ...nbr) {
            StringBuilder tmp = new StringBuilder();
            for (int n : nbr) {if (isPrime(n)) tmp.append(n).append(" ");}
            System.out.println(tmp);
        }
        private boolean isPrime(int n) {
            if (n <= 1) return false;
            for (int i = 2; i <= Math.sqrt(n); i++) 
               {if (n % i == 0) return false;}
            return true;
        }
        
    };