title: Remove trailing zeros in the output of an integer array in java
body: <p>In my code, I get an output of an array but it displays some unwanted zeros after getting the array, Can you explain a way to avoid getting these unwanted zeros.</p>
  
  <pre><code> static int[] cutTheSticks(int[] arr) {
   int min,i,j,count=0;
   int []arr2=Arrays.copyOf(arr,arr.length);
   int []temp =Arrays.copyOf(arr,arr.length);
  
  
      for(i=0;i&lt;arr.length;i++){
          Arrays.sort(arr2);
          min= arr2[0];
          for(j=0;j&lt;arr.length;j++){
  
              if(temp[j]&gt;0){
                  count++;
              }
              temp[j]=temp[j]-min;
  
          }
          int []res = new int [arr.length];
          while(count!=0) {
              res[i] = count;
              count = 0;
  
      }
      return res;
  
  
  
    }
  </code></pre>