In this HackerRank Prime Checker problem in java, you are given a class Solution and its main method in the editor. Your task is to create a class Prime. The class Prime should contain a single method checkPrime.

HackerRank Prime Checker in java problem solution

HackerRank Prime Checker in java problem solution

import static java.lang.System.in;

class Prime{
    private static final BitSet erat;
    static{
        erat = new BitSet(1024);
        erat.set(2, 1025);
        for (int i = 2; Math.pow(i, 2) <= 1024; i++){
            if (erat.get(i)){
                for (int j = (int)Math.pow(i, 2); j <= 1024; j += i){
                    erat.clear(j);
                }
            }
        }
    }
    public void checkPrime(Integer... args){
        for (int i : args){
            if (isPrime(i)){
                System.out.print(i+" ");
            }
        }
        System.out.println();
    }
    private boolean isPrime(int i){
        if (erat.get(i)){
            return true;
        }
        return false;
    }
}