fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] unsorted = {
  13. -3, 95, -4, 20, 5, 6, 8
  14. };
  15.  
  16. int[] positives = new int[unsorted.length];
  17.  
  18. int i = 0, j = 0;
  19.  
  20. for (; i < unsorted.length; i++) {
  21. if (unsorted[i] >= 0)
  22. positives[j++] = unsorted[i];
  23. }
  24.  
  25. positives = Arrays.copyOf(positives, j);
  26.  
  27. Arrays.sort(positives);
  28.  
  29. for (int k : positives)
  30. System.out.println(k);
  31.  
  32.  
  33. }
  34. }
Success #stdin #stdout 0.06s 380224KB
stdin
Standard input is empty
stdout
5
6
8
20
95