Unexpected output using System.err.println() in java -


this question has answer here:

i tried executing following print statements in java, output got unexpected. output jumbled.

public class asynctestclass { public static void main(string[] args) {      system.out.println("1");     system.out.println("2");     system.out.println("3");     system.out.println("4");     system.out.println("5");     system.err.println("error");     system.out.println("6");     system.out.println("7");     system.out.println("8");     system.out.println("9");     system.out.println("10");           }  } 

first run output:

1 error 2 3 4 5 6 7 8 9 10 

second run output:

     1 2 3 4 5 error 6 7 8 9 10 

third run output:

    1 error 2 3 4 5 6 7 8 9 10 

why getting different outputs same code??

they different streams , flushed @ different times.

system.out.flush(); system.err.flush(); 

you can take stack-question


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -