# Prime Numbers Between Range Java Example

by Dinesh Thakur Category: Control Structures

Algorithm For Prime Numbers between Range:

step 1: Set num=1

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 static void main(String args[])

{

int num =1,b,c,range;

Scanner s=new Scanner(System.in);

System.out.println("Enter The Range \n");

range=s.nextInt();

while(num <=range)

{

b=1;

c=0;

while(b<= num)

{

if((num%b)==0)

c=c+1;

b++;

}

if(c==2)

System.out.println(num +" is a prime number");

num ++;

}

}

}

``` Dinesh Thakur holds an B.SC (Computer Science), 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