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