2

I'm programming Java using Eclipse and I discovered a weird behavior of System.out.print when printing long arrays. Using the following code prints a long line of blanks before the actual output:

double[] values = new double[1000];
for (int i=0; i<1000; i++)
    values[i] = Math.random();
for (int i=0; i<1000; i++)
    System.out.print(values[i] + " ");

enter image description here

But when I change the array length to 100 it works as expected: enter image description here

Can someone explain this? Is it related to Java or to Eclipse?

Rob
  • 26,989
  • 16
  • 82
  • 98
stefanbschneider
  • 5,460
  • 8
  • 50
  • 88
  • 2
    It's more like a problem in Eclipse and it's "console" implementation. Run that program from another IDE or a "real" console and see if this problems stays. – Tom Dec 09 '14 at 09:10
  • Confirmed that its an Eclipse problem. Those are not blanks, they are actually values. If you copy those values, and paste in a text editor, you can see actual values. There were no problems when I used an online Java compiler(http://codingground.tutorialspoint.com/) – Master Chief Dec 09 '14 at 09:15

4 Answers4

0

This is related to output limit of console in eclipse. You can increase it from Preference > Run/Debug > Console > Console buffer size.

there is not problemw when i tried from command prompt

Panther
  • 3,312
  • 9
  • 27
  • 50
0

Confirmed that its an Eclipse problem. Those are not blanks, they are actually values. If you copy those values, and paste in a text editor, you can see actual values. There were no problems when I used an online Java compiler(codingground.tutorialspoint.com)

You can check this link for more info Eclipse console doesn't show the whole output

Community
  • 1
  • 1
Master Chief
  • 2,520
  • 19
  • 28
0

try changing the eclipse console settings:

  • enable "Fixed width console"
  • disable "Limit console output"
  • This helped me solve an an issue I had when I tried to print a large-size array and the elements overlapped each other in the console. – alexandrosangeli Jan 27 '21 at 08:52
0

Eclipse supports only the 1000 characters per row. If you open Preferences -> Run/Debug-> Console and enable Fixed with console, it won't allow you to enter more that 1000. Seems that's the issue, so when you uncheck it you only see the last 1000 characters. If you enter 1000 you would be able to see all the characters.

Sudarshan
  • 43
  • 1
  • 5