Menu Bar

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Friday, 11 November 2016

Java Program to check Number is Prime or Not ?

Previously we Have Discussed the Program for


A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number.

public class NumberIsPrimeOrNot {

public static boolean isPrime(int num){
for(int i=2;i<=num/2;i++){
 if(num % i == 0){
 return false;
 }
}
  return true;
}
public static void main(String[] args) {
System.out.println("IS 17 PRIME NUMBER : "+NumberIsPrimeOrNot.isPrime(17));
System.out.println("IS 5 PRIME NUMBER : "+NumberIsPrimeOrNot.isPrime(5));
System.out.println("IS 25 PRIME NUMBER : "+NumberIsPrimeOrNot.isPrime(25));
}
 
}

Program Output :

IS 17 PRIME NUMBER : true
IS 5 PRIME NUMBER : true
IS 25 PRIME NUMBER : false


      
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



Share this Blog with yours Friends !!

No comments:

Post a Comment