The code runs perfectly in my IDE but ideone shows run time error. I am not able to figure out the problem.Below is my code.
import java.util.Scanner;
class Main {
public static void main(String args[])
{
int n,l, i=2, res=0,j,flag=2;
Scanner sin=new Scanner(System.in);
n=sin.nextInt();
if(n<10)
{
for(l=1;l<=n;l++){
Scanner scan=new Scanner(System.in);
String s=scan.nextLine();
String f[]=s.split(" ");
int a=Integer.parseInt(f[0]);
int b=Integer.parseInt(f[1]);
if(1<=a && a<=b && b<=1000000000 && (b-a)<=100000){
for(j=a;j<=b;j++){
flag=2;
for(i=2;i<=j;i++)
{
res=j%i;
if(res==0 && i!=j){}
else if(res!=0){
flag++;
}
}
if(flag+1==i)
System.out.println(j);
}
}
}
}
}
}