1

I have a simple loop that does n = n ^ 2, where n is a BigInteger. But, after the 11th iteration of the loop (I currently have it set to not go further because of this issue), the console goes blank, but filled with spaces. Like there should be characters there but there aren't. This is evident as it's highlight-able. My question is; is there a cap on BigIntegers, a max displayable output, or am I just not giving my CPU enough time do the calculation?

import java.math.*;

public class Main {
    static BigInteger n = BigInteger.valueOf(123);
    static int j = 11;
    public static void main(String[] args) {
        while(j != 0) {
            System.out.println(n);
            n = n.pow(2);
            j--;
        }
        System.out.println("Done. ");
    }
}
IHazABone
  • 525
  • 2
  • 6
  • 20
  • Your code works for me. Java version, console type? – William Gaul Oct 03 '13 at 01:36
  • 1
    have a look at http://stackoverflow.com/questions/6791970/how-to-get-biggest-bigdecimal-value – Scary Wombat Oct 03 '13 at 01:37
  • It works as per what I have posted. However, if `j` is any higher or the loop is infinite, the problem I described comes up. – IHazABone Oct 03 '13 at 01:37
  • 1
    @IHazABone It worked for `j = 20` for me. Took a while, but it worked. There is an upper bound (see the link in the other comment) but it's implementation dependent. So yeah, maybe RAM issues or your CPU just needs more time. – William Gaul Oct 03 '13 at 01:40
  • I've got plenty of RAM and a rather powerful CPU, but the JVM limits RAM usage to 4GB, doesn't it? Okay, I'll try it again. Thanks. – IHazABone Oct 03 '13 at 01:45
  • With `j = 20` it comes up blank with "Done. " as the only output, the first 11 numbers seemed to have gotten erased. – IHazABone Oct 03 '13 at 01:55

0 Answers0