Printing very big BigIntegers

匆匆过客 提交于 2019-12-01 17:27:55

The problem is a bug of the Console view in Eclipse.

On my setup, Eclipse (Helios and Juno) can't show a single line longer than 4095 characters without CRLF. The maximum length can vary depending on your font choice - see below.

Therefore, even the following code will show the problem - there's no need for a BigInteger.

StringBuilder str = new StringBuilder();
for (int i = 0; i < 4096; i++) {
    str.append('?');
}
System.out.println(str);

That said, the string is actually printed in the console - you can for instance copy it out of it. It is just not shown.

As a workaround, you can set Fixed width console setting in Console preferences, the string will immediatelly appear:

The corresponding bugs on Eclipse's bugzilla are:

According to those, it's a Windows/GTK bug and Eclipse's developers can't do anything about it.

The bug is related to the length of the text is pixels, use a smaller font and you will be able to get more characters in the text before it breaks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!