Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get rid of this overflow error?
    primarykey
    data
    text
    <p>I am having a code, which gives incorrect output as i am working with big numbers. I want a solution to this that how could i improve this to accommodate big numbers. <strong>Which datatype i should use?</strong></p> <p>CODE:</p> <pre><code> static int get(int n,int i,int digit) { int p; p=(int)Math.pow(10,i-1); n=n/p; return n%10; } static boolean check_pal(int n) { int digit; digit=(int) (Math.log10(n)+1); int a=0,b=0,i,j,p; int sum=0; for(i=1,j=digit-1 ; i&lt;=digit ; i++,j-- ) { a=(int) get(n,i,digit); sum+=a*Math.pow(10,j); } if(sum==n) return true; else return false; } static int reverse(int n) { int digit; digit=(int) (Math.log10(n)+1); int a=0,b=0,i,j,p; int sum=0; for(i=1,j=digit-1 ; i&lt;=digit ; i++,j-- ) { a=(int) get(n,i,digit); sum+=a*Math.pow(10,j); } return n+sum; } public static void main(String[] args) { try{ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n&lt;10 || n&gt;999){ System.out.println("None"); return;} boolean c; for(int i=1 ; i&lt;=100 ; i++) { System.out.println("iteration"+i+" value is "+n); c=check_pal(n); if(c==true) { System.out.println(n); return; } n=reverse(n); } System.out.println("None"); } catch(Exception e) { System.out.println("NONE"); } } </code></pre> <p>Here is output: <img src="https://i.stack.imgur.com/Zt8mp.jpg" alt="output"></p> <p>In output, Iteration 17th get negative value this shows overflow. I want a solution so that this work for all inputs between 10 to 999.</p> <p>Here is problem definition <a href="http://www.codechef.com/problems/RBX1314" rel="nofollow noreferrer">click here !!</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload