NoSuchElementException occuring

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner in =new Scanner(System.in);
int n=in.nextInt();
int a,b;
int count=0;
for(int j=1;j<=n;j++)
{
a=in.nextInt();
b=in.nextInt();
count=0;

    for(int i=a;i<=b;i++)
    {
        if(prime(i)==true)
        count++;
    }

    System.out.println(count);
    }
}
public static boolean prime(int i)
{
    boolean g=true;
    for(int p=2;p<i;p++)
    {
        if(i%p==0)
        {
            g=false;
            break;
        }
    }
    return g;
}

}

Put the sample input in the input box and then run. If sample input is already present in the input box, then cut paste it and then run. Should work