1 / 6
Jan 2020

I was trying to solve the problem on Java even though the code is working on my IDE it is giving an error on SPOJ can someone help me with what am I going wrong?

This is my code :

import java.util.Scanner;
import java.lang.*;

/**
*

  • @author RAHUL KUMAR JHA
    */
    public class Main {

static int rev(int p){ //Reverse Driver
int temp,rev=0;
while(p!=0){
temp=p%10;
rev=(rev*10)+temp;
p=p/10;
}
return rev;
}
static int pal(int q){//Pallindrome Driver
boolean flag=false;
while(flag!=true){
int k=rev(q);
if(q==k){
flag=true;
}
else{
++q;
}

        }

    return   q;
}
public static void main(String[] args)throws Exception {
    try{
    Scanner read=new Scanner(System.in);
    int var=read.nextInt();
    for (int i=0;i<var;i++){
        int a=read.nextInt();
        System.out.println(pal(++a));
    }}
    catch (Exception e){
    	return;
    }
    }
    
}

You’ve not noticed how big the integer can be. It’s not going to fit in an int or long or long long.

The problem clearly states that the size of the integer is not be larger than i=1000000 however my program clearly working for integer larger than this I still don’t get the problem ?

You need to read that bit again. It says the integer can have up to 1 million digits.

Something that can hold 1 million numeric characters.