Help me in this problem

Hello Everyone!!
I m new to Java programming though i now a bit of C++. Can anyone tell me where i am getting an error.

import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    int T,N,count=0,i;
	    T=Integer.parseInt(br.readLine());
	    while(T>0)
	    {
	        N=Integer.parseInt(br.readLine());
	        Long A[] = new Long[N];
	        Long B[] = new Long[N];
	        String input1[] = br.readLine().split(" ");
	        String input2[] = br.readLine().split(" ");
	        for(i=0;i<N;i++)
	        {
	            A[i]=Long.parseLong(input1[i]);
	            B[i]=Long.parseLong(input2[i]);
	        }
	        for(i=0;i<N;i++)
	        {
	            if(i==0)
	            {
	                if(A[i]>=B[i])
	                {
	                    count++;
	                }
	            }
	            else
	            {
	                if((A[i]-A[i-1])>=B[i])
	                {
	                    count++;
	                }
	            }
	        }
	        System.out.println(count);
	        count=0;
	    }
	}
}

For better understanding the link to my code is :-
https://www.codechef.com/viewsolution/14269215

The error shown is:-

Exception in thread “main” java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Integer.java:542) at java.lang.Integer.parseInt(Integer.java:615) at Codechef.main(Main.java:14)

Your while loop will run forever. Don’t forget to decrement T.

1 Like

while(T>0)

This is error. You are running loop till T>0, but you are NOT UPDATING T. This leads to an infinite loop, but BEFORE it could throw you a TLE, it runs out of input values, and hence you get the above exception. Adding a “T=T-1” or “T–” changing loop to “while(T–>0)” fixed the problem.

(NOTE- Dont use “–T>0”, it will cause 1 iteration less as it first changes value and then updates. Use --T>=0 instead)

1 Like

Lmao XD. 2min difference b/w answers :stuck_out_tongue: