Java buffered reader

in this code there is no compilation error but , it is not reading input or the execution is not going beyond first input statement .
i am used to scanner and unable to understand the problem is.

code:_

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

class Codechef
{
public static void main (String[] args) throws IOException
{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
while(true)
{ try
{
System.out.println(“abc”);
int t= Integer.parseInt(br.readLine()); \gets exectuted
System.out.println(t);
for(int i=0;i<t;i++)
{
System.out.println(t);
int k= Integer.parseInt(br.readLine()); \does not gets executed
System.out.println(k);
System.out.println(t);
}
}

catch(Exception e)
   {
    return;
	}

}}
}

In the above code when i give input for just ‘t’ all the print statement get executed , but when input ‘t’ and ‘k’ is given the output is only “abc”.

It seems you have inputted multiple values on a single input line for either t or k or both.

If that is the case, refer this page to see how to do that:

Example:

public static void main(String[] args) {
    Scanner in = new Scanner(System.in); 
    while (in.hasNext()) {
        if (in.hasNextInt())
            System.out.println(in.nextInt());
        else 
            in.next();
    }
}
1 Like

thank you.