Java Topics

Print whether the given number is prime number or not ?

public class PrimeNumber {

public static void main(String[] args) {

int n=5;

int count=0;

for(int i=2;i<=n;i++) {

if(n%i==0) {

count++;

}

}

       if(count==1) 

       System.out.println("number is prime"); 

       else 

       System.out.println("number is not prime");

}

}

Output:

number is prime