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) {
  11. int array[] = {33,55,13,46,87,42,10,34,43,56};
  12. int mArray[] = new int[5];
  13. int j = 0;
  14.  
  15. for(int i = 0; i < array.length; i++) {
  16. if (array[i] > lower(mArray)) {
  17. mArray[lowerPos(mArray)] = array[i];
  18. }
  19. }
  20.  
  21. System.out.println(Arrays.toString(mArray));
  22. }
  23.  
  24. public static int lower(int[] array) {
  25. int lower = Integer.MAX_VALUE;
  26. for (int n : array) {
  27. if (n < lower)
  28. lower = n;
  29. }
  30. return lower;
  31. }
  32.  
  33. public static int lowerPos(int[] array) {
  34. int lower = Integer.MAX_VALUE;
  35. int lowerPos = 0;
  36. for (int n = 0; n < array.length; n++) {
  37. if (array[n] < lower) {
  38. lowerPos = n;
  39. lower = array[n];
  40. }
  41. }
  42.  
  43. return lowerPos;
  44. }
  45. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
[43, 55, 56, 46, 87]