Where we learn technology

How to find Prime Number

How to find Prime Number in Java

Learn:
1. check the given number is prime or not.
2. print all the prime numbers upto a given a number
3. write different test cases

Code:

package Questions;
public class PrimeNumber {
//2 is the lowest prime number
//3
//num = 20
public static boolean isPrimeNumber(int num){
//edge/corner cases:
if(num<=1){
return false;
}
for(int i=2; i<num; i++){
if(num % i == 0){
return false;
}
}
return true;
}
public static void getPrimeNumbers(int num){
for(int i=2; i<=num; i++){
if(isPrimeNumber(i))
System.out.print(i + ” “);
}
}
public static void main(String[] args) {
System.out.println(“2 is prime number: “+ isPrimeNumber(2));
System.out.println(“3 is prime number: “+ isPrimeNumber(2));
System.out.println(“10 is prime number: “+ isPrimeNumber(10));
System.out.println(“17 is prime number: “+ isPrimeNumber(17));
System.out.println(“0 is prime number: “+ isPrimeNumber(0));
System.out.println(“1 is prime number: “+ isPrimeNumber(0));
System.out.println(“-3 is prime number: “+ isPrimeNumber(-3));
getPrimeNumbers(7);
getPrimeNumbers(13);
getPrimeNumbers(20);
}
}

9 Comments

  1. Praylin S

    Thanks for sharing this awesome post! This is really informative and I was searching for this. This'll be really helpful. Keep us updated with more such posts.
    Excel Training in Chennai
    Advanced Excel Training in Chennai
    VMware Training in Chennai
    VMware Course in Chennai
    Manual Testing Training in Chennai
    Manual Testing Courses in Chennai
    Excel Training in Anna Nagar
    Excel Training in T Nagar

  2. andrewmathew

    Magnificent beat ! I wish to apprentice while you amend your web site, how could i subscribe for a blog web site? The account helped me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright clear concept inbound marketing

  3. Chris Hemsworth

    The article is so informative. This is more helpful for our
    selenium training in chennai
    selenium online courses best selenium online training
    selenium testing training
    selenium classes
    Thanks for sharing.

  4. Naveen S

    This is the first & best article to make me satisfied by presenting good content. I feel so happy and delighted.By Learn Digital Marketing Course Training in Chennai it will help to get Digital Marketing Course Training in Chennai.Learn Best Digital Marketing Course Training in Chennai's professional institute to get reputed job.

  5. Jackie Co Kad

    The development of artificial intelligence (AI) has propelled more programming architects, information scientists, and different experts to investigate the plausibility of a vocation in machine learning. Notwithstanding, a few newcomers will in general spotlight a lot on hypothesis and insufficient on commonsense application. IEEE final year projects on machine learning In case you will succeed, you have to begin building machine learning projects in the near future.

    Projects assist you with improving your applied ML skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include projects into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Final Year Project Centers in Chennai even arrange a more significant compensation.

    Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account.

  6. rthwer

    This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses. ソンウルナンバー占いい

Leave a Reply

Your email address will not be published. Required fields are marked *