How to find a Number is Prime Number or Not

How to find a Number is Prime Number or Not
SOURCE : PrimeNumber.java

public class PrimeNumber {
public static void main(String[] args) {

PrimeNumber pm = new PrimeNumber();

System.out.println("number is prime ? : " + pm.pmnum(23));

}

public boolean pmnum(int num) {

for (int i = 2; i < num / 2; i++) {

if (num % i == 0) {

return false;

}

}

return true;

}

}


INPUT

23



OUTPUT

number is prime ? : true






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment