I have this code. This code simply creates an array of size 1,000,000 to hold randomly generated integers. My problem is that i want to print 10 integers per line and the output is so strange and i don`t know why. I debugged the code and found that the code must work as expected. Though, it acts strangely. I will be grateful if anyone can help me. This is my code:
Integer[] list = new Integer[1000000];
for(int i = 0 ; i < list.length ; i++)
list[i] = (int)(Math.random() * 1000);
//print 10 integers per line
for(int i = 0 ; i < list.length ; i++){
if( (i+1) % 10 == 0)
System.out.printf("%-5d\n" , list[i]);
else
System.out.printf("%-5d" , list[i]);
}
I attach a screenshot of the output.

By the way: I use Intellij IDEA.
Console cycle buffer size is 1024 KB (default for Intellij idea), you can see it in Settings -> Editor -> General -> Console. So your 1,000,000 random numbers more than that. In the first line of your console after program is executed, you do not see real first line, it is somewhere in the middle of process. So, that line is cut. If you print 1000 numbers, you will see that your code works fine.
Edit:
In above-mentioned settings location, there is an option Override console buffer size, click on the check box, increase buffer size. When size is big enough, you can see all your numbers in the form of 10 numbers per line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With