import java.io.*;
class today{
public static void main(String args[])throws IOException{
int q;
long a;
long b;
BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
q=Integer.parseInt(br.readLine());
while(q>0)
{
a=Long.parseLong(br.readLine());
b=Long.parseLong(br.readLine());
if(((a-b)==2)||((b-a)==2))
System.out.println("yes");
else if(((a/2)-(b/2)==1))
System.out.println("yes");
else
System.out.println("no");
q--;
}
}
}Asked by: Jayant_Mishra on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.
Error is in the following line
a=Long.parseLong(br.readLine());
b=Long.parseLong(br.readLine());
In the input, two space seaparated integers are given in a single line.
br.readLine() reads entire line. Thus, for the first query of sample input(the one given in input example of the question) it will return string "1 4". By using Long.parseLong(), you are trying to convert a string(here it is "1 4") containing space into a number. This will result in runtime error.
The solution for this would be:
String[] temp = br.readLine().split();
a = Long.parseLong(temp[0]);
b = Long.parseLong(temp[1]);
Alternatively, you can use user-defined functions for faster input/output. Here, is the link for this. Below is the is the method to take input in the given case.
a = nl();
b = nl();