Thanks, I changed the main method to this, but still getting the error 
public static void main(String[] args) throws java.lang.Exception {
ArrayListnums = new ArrayList();
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String x=input.readLine();
int k=0;
while(k==0) {
try{
k = Integer.parseInt(x);
}
catch(Exception e) {
x=input.readLine();
}
}
int y;
for(int i=0;i<k;i++) {
y=Integer.parseInt(input.readLine());
int c = y;
while(x.length()<1000000) {
c++;
if(c==reverse©) {
nums.add©;
break;
}
}
}
for(int b = 0;b<nums.size();b++) {
System.out.println(nums.get(b));
}
}