When I run my code using BufferedReader
class as well as util class and initialising the variables outside the StringTokenizer
using BufferedReader
class then it works but when I use this it breaks and I get java.util.NoSuchElementException
error as I input the first String s(in the code).
import java.util.*;
class spamclas
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int a=0,b=0;
int t=sc.nextInt();
while(t>0)
{
String s=sc.next();
StringTokenizer st=new StringTokenizer(s);
while(st.hasMoreTokens())
{
a = Integer.parseInt(st.nextToken());
b = Integer.parseInt(st.nextToken());
}
System.out.println("a b"+a+" "+b);
t--;
}
}
}