Question: you have to check for n test cases that multiplication of a and b is equal to 3rd input value or not.If equal then print YES otherwise NO. Input: 2 5 6 30 4 3 20
Output: YES NO
Explanation: 2 is number of test cases. 5 is a & 6 is b ,multiplication is 30 so YES
Constraints :
0 < test cases <= 1000000000 0 < a < b <= 10000000
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Scanner;
class ques1
{
public static void main(String[] args) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Scanner sc=new Scanner(System.in);
BigInteger test=new BigInteger(sc.next());
while(!test.equals(BigInteger.ZERO))
{
Scanner s=new Scanner(br.readLine());
s.useDelimiter(" ");
BigInteger p=new BigInteger(s.next());
BigInteger q=new BigInteger(s.next());
BigInteger r=new BigInteger(s.next());
if(p.multiply(q).equals(r))
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
test=test.subtract(BigInteger.ONE);
}
}
}
This program is working fine in eclipse.But while running on online compilers like ideone.com,etc it is giving error message as following:
Exception in thread "main" java.lang.NullPointerException
at java.io.StringReader.<init>(StringReader.java:50)
at java.util.Scanner.<init>(Scanner.java:702)
at ques1.main(Main.java:18)
Constraints are so big so i am using biginteger.I had also used stringtokenizer instead of scanner of input separation,but it is also giving same error. i have to take input in a spacing format so i am using stringtokenizer or scanner. Is there is any other way to separate them.
br.readLine()is throwing the NPE, is there a line for it to read..?br.readLine()==null, beforenew Scanner().