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 array[] = {5, 3, 2, 8, 1, 4};
  13.  
  14. int[] sortedArray = new int[array.length];
  15. System.arraycopy(array, 0, sortedArray, 0, array.length);
  16.  
  17. for (int i = 0; i < sortedArray.length - 1; i++)
  18. {
  19. /* is current odd, if so search next odd */
  20. if (sortedArray[i] % 2 != 0)
  21. {
  22. /* search for next odd and compare */
  23. for (int j = i + 1; j < sortedArray.length; j++)
  24. {
  25. if ((sortedArray[j] % 2 != 0) && (sortedArray[i] > sortedArray[j]))
  26. {
  27. int temp = sortedArray[i];
  28. sortedArray[i] = sortedArray[j];
  29. sortedArray[j] = temp;
  30. }
  31. }
  32. }
  33. }
  34. for (int i: sortedArray)
  35. {
  36. System.out.println(i);
  37. }
  38. }
  39. }
Success #stdin #stdout 0.03s 4386816KB
stdin
Standard input is empty
stdout
1
3
2
8
5
4