Click Here to get Free Trader Applications

import java.util.Scanner;

public class Primeintervals
{
public static void main(String args[])
{
// initialize and declare here.
int s1=20, s2=30,count = 0, i, j;
// Scanner s = new Scanner(System.in);
// System.out.print("Enter the lower limit : ");
// s1 = s.nextInt();
// System.out.print("Enter the upper limit :");
// s2 = s.nextInt();
System.out.println("Prime numbers between given range are :");

for(i = s1; i<= s2; i++)
{
for( j = 2; j < i; j++)
{
if(i % j == 0)
{
count = 0;
break;
}
else
{
count = 1;
}
}
if(count == 1)
{
System.out.println(i);
}
}
}
}

Post a Comment

Previous Post Next Post