1 / 4
Feb 2020

Please check my below code

package practice;

import java.util.Scanner;

public class Main {

public static void main(String arg[]) {

	Scanner sc = new Scanner(System.in);
	try {
		int n = sc.nextInt();
		for (int i = 0; i <= n - 1; i++) {
			Long number = sc.nextLong();
			if (number >= 1000000) {
				System.out.println("-1");
			}
			StringBuilder reverseIt;
			for (long j = number + 1; j < 9999999; j++) {
				reverseIt = new StringBuilder();
				reverseIt.append(j);
				if (j == Integer.parseInt((String) reverseIt.reverse().toString())) {
					System.out.println(j);
					break;
				}
			}

		}
		return;

	} catch (Exception e) {
	}
}

}

  • created

    Feb '20
  • last reply

    Feb '20
  • 3

    replies

  • 801

    views

  • 2

    users

  • 2

    links

You’ve misread the constraints - the integer can be up to one million digits, not up to one million.

thanks for rply can u help me out what i need to update here after removing whose constraints the error is coming up

Of course, because you can’t store an integer that big in any Java integer variable. You need to come up with an alternative.

This3 or this4 might help.