My code for problem PLAYING WITH BITS is throwing InputMismatchException. But it is running fine in my compiler.
import java.util.Scanner;
public class Solution
{
public static int countBits(int result)
{
int count=0;
while(result>0)
{
count+=(result&1);
result=result>>1;
}
return count;
}
public static void main(String[] args)
{
Scanner reader=new Scanner(System.in);
int t=reader.nextInt();
while(t-- > 0)
{
int a=reader.nextInt();
int b=reader.nextInt();
int count=0;
for(int i=a;i<=b;i++)
{
count+=countBits(i);
}
System.out.println(count);
}
reader.close();
}
}