by Dinesh Thakur Category: Control Structures

Algorithm For Prime Numbers between Range:

step 1: Set num=1

step 2: Read range

step 3: Repeat through step-9 while num less than or equals to range

step 4: Initialize b= 1, c=0

step 5: Repeat through step-7 while b less than or equals to num

step 6: If (num mod b) equals to 0 then set c=c+1

step 7: b=b+1

step 8: If c equals to 2 then print num

step 9: num =num +1

step 10: Exit

Here is the Java Example for Prime Numbers between Range:

import java.util.Scanner;

public class PrimeNumberBetweenRange
                  public static void main(String args[])
                   int num =1,b,c,range;
                 Scanner s=new Scanner(;
                 System.out.println("Enter The Range \n");
                 while(num <=range)
                           while(b<= num)
                      System.out.println(num +" is a prime number");
                                    num ++;

Prime Numbers between Range

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles