1 / 4
Mar 2022

no errors in ideone, not sure what is causing the error.
import java.util.;
import java.io.
;
public class Main {
public static int reverse(int z) {
String q = Integer.toString(z);
String rev = “”;
for(int h=1;h<=q.length();h++) {
int div=10;
div=(int) Math.pow(div, h);
rev+=Integer.toString((z%div)/(div/10));
}
z=Integer.parseInt(rev);
return z;
}
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=1000000;
int y;
for(int i=0;i<Integer.parseInt(x);i++) {
y=Integer.parseInt(input.readLine());
for(int j=0;j<K;j++) {
int c= y+j;
if(c==reverse©) {
nums.add©;
break;
}
}
}
System.out.println(nums);
}
}

  • created

    Mar '22
  • last reply

    Mar '22
  • 3

    replies

  • 569

    views

  • 2

    users

  • 2

    links

Did you notice how big the number can be? 1,000,000 digits.

Thanks, I changed the main method to this, but still getting the error :frowning:

public static void main(String[] args) throws java.lang.Exception {
ArrayListnums = new ArrayList();
BufferedReader input = new BufferedReader(new InputStreamReader(System.in1));
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));
}
}

I don’t think you understood what I said in my previous comment. The number is not up to 1,000,000, but is up to 1,000,000 DIGITS long. So it won’t fit in an int.