Prime Checker

  • + 0 comments
    import java.lang.System.in;
    
    class Prime {
    	public void checkPrime(int... num){
    		int count = 0;
    		for (int n : num){
    			if(n == 2){
    				System.out.print(n + " ");
    			} 
    			if (n > 2){
    				for(int i=2;i <= Math.sqrt(n);i++){
    						if(n%i == 0){
    							count++;
    						}
    				}
    				if(count==0){
    					System.out.print(n + " ");
    				}
    				count = 0;
    			}
    		}
    		System.out.println();
    	}
    }