Yes i think I am checking every second divisor "z=z-2" because it is only for odd numbers so I am checking
only odd divisors. I have changed my code around
import java.util.Scanner;
public class PrimeNumbers {
static boolean primecheck(int n)
{
for(int i=2;i<n;i++) {
if(n%i==0)
return false;
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a;
a=sc.nextInt();
for(int x=0; x<a; x++)
{
int one, two;
one=sc.nextInt();
two=sc.nextInt();
for (int i=one; i<=two; i++)
{
if(i==2)
{
System.out.println(i);
}
else
{
if(i%2!=0&&i>2)
{
if(primecheck(i)==true)
{
System.out.println(i);
}
}
}
}
}
}
}
I have changed while loop to for loop and put it in boolean method and changed this long if to i%2==0 as it looks much better now.
however I still havent got a clue how to improve the speed of the calculation