Program to print all the prime numbers between given range in Java

Posted by Nilendra Kumar | Updated on

In this example, I have shared a Java program to print all the prime numbers between given range. This program takes two input numbers a and b as interval range, and finds find all the prime numbers in between the interval.

Algorithm to find prime numbers

  1. Take the range of numbers between which you have to find the prime numbers as input.
  2. Check for prime numbers only on the odd numbers between the range.
  3. Also check if the odd numbers are divisible by any of the natural numbers starting from 2.
  4. Print the prime numbers and its count.

Program to print all the prime numbers between given range

Program output

This program is contributed by Nilendra Kumar. Here is same the program using C programming language.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers