java - System out println -


i'm printing 2 lines console. both print, when second 1 has printed, first 1 changes second one, 2 lines identical. i've never encountered before. why second print overwrite first one, , how fix it?

public static void main(string args[]){     new mergesort(90000);      system.out.println("array mergesorted: " +arrays.tostring(array));      long start = system.currenttimemillis();      mergesort(array, 1, array.length);      long end = system.currenttimemillis();      system.out.println("result: " + arrays.tostring(array) ); } 

the constructor:

public mergesort(int n){     random rand = new random();     array = new int[n];     for(int = 0; <array.length; i++){         array[i] = rand.nextint(101);     } } 

rest of code:

public static void merge(int[] a, int p, int q, int r){     //     //length of subarray 1     int n1 = q-p+1;      //length of subarray 2     int n2 = r-q;      int[] l = new int[n1+1];     int[] r = new int[n2+1];      for(int = 0; < n1; i++){         l[i] = a[p+i-1];     }      for(int j=0; j< n2; j++){         r[j] = a[q+j];     }      l[n1] = integer.max_value;     r[n2] = integer.max_value;      int = 0;     int j = 0;      for(int k = p-1; k < r; k++){         if(l[i] <= r[j]){             a[k] = l[i];             i++;         }         else{                 a[k] = r[j];                 j++;             }     }  }  public static void mergesort(int[] a, int p, int r){     if (p<r){         int q = (int) math.floor((r+p)/2);         mergesort(a, p, q);         mergesort(a, q+1, r);         merge(a, p, q, r);     } } 

this due buffer limit of console in ide. cannot explain why seeing duplicate output of strings other looks theres bug in how clears out old characters in buffer when hits limit.

i think eclipse comes default of 80,000 character limit in console output. since printing 90,000 numbers between 1-100 2 times means on shooting buffer , some.

to increase buffer limit on console:

  • right click on output window in eclipse , select perferences
  • change "console buffer size (characters)" desired limit.

ideally change higher maximum characters printing out program. maybe 800,000?


heres picture of preferences window. enter image description here

edit: question reminded me of another interesting question in answer question lied inside how word wrapping performed in terminal output. not same question related , quite interesting question/answer. worth read , there's lesson learned in of this.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -