The program provides the correct output for println (String s); but do not print (String s); What for?

Below is the code that is having problems:

public class testOutput { public static void main(String[] args) throws Exception { int count = 50000; String s = "Vinjith"; for(int i=0;i<count;i++) { System.out.print(s); // change this to println(s); and it works! System.out.flush(); } } } 

I am using Eclipse Galileo - jdk 1.6 / jre6.

  • I do not set a limit on console output.
  • I also tried the same program with BufferedWriter: not working
  • It works when the variable count = 584; no more.
  • I get no output when I use System.out.print (s); but when I use System.out.println (s); I get 50,000 lines of "Vinjith" string.

Thanks.

+4
source share
3 answers

This is because there are too many characters on one line where Eclipse does not support this on its console (you will not see anything on the console). Try using the same code on the command line and it should work.

+2
source

This is because the length of the characters you type in the Eclipse console is out of bounds.

Try this and see if it prints.

 System.out.print(s); // change this to println(s); and it works! System.out.println(); System.out.flush(); 

Also, regarding a limit problem, just try this. In the settings → run / debug → console, the Fixed Width Console checkbox will appear. Its maximum limit is 1000 . Try to do this 1000 and run the source code as shown below. You will see that it prints some characters, and for the rest - Internal Error .

 System.out.print(s); // change this to println(s); and it works! System.out.flush(); 
+1
source

Have you tried this:

  for(int i=0;i<count;i++) { System.out.print(s); // change this to println(s); and it works! } System.out.println("---done"); System.out.flush(); 

What happens when you try to use count values ​​(100, 500, 1000, 2000, 10000, etc.)?

Please post the output when it works, and what is "count".

I have studied flush() problems before, and it comes down to how your OS internally handles buffers. Most JREs only define an interface and then rely on the OS to implement the actual behavior, and in some cases this is strange. See my answer to a close question.

0
source

All Articles