fork(2) 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 String toString(Float[] a)
  11. {
  12. String s = "[";
  13. int i = 0;
  14. for (; i < a.length - 1; i++)
  15. {
  16. s += a[i] + ", ";
  17. }
  18.  
  19. s += a[i] + "]";
  20. return s;
  21. }
  22.  
  23. public static float m(Float[] a)
  24. {
  25. Arrays.sort(a);
  26. int l = a.length;
  27. float n = a[l / 2];
  28. return l % 2 > 0 ? n : (a[l / 2 - 1] + n) / 2;
  29. }
  30.  
  31. public static void main (String[] args) throws java.lang.Exception
  32. {
  33. Float[][] input =
  34. {
  35. { 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f },
  36. { 1f, 4f, 3f, 2f },
  37. { 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, -5f, 100000f, 1.3f, 1.4f } };
  38.  
  39. for (Float[] a : input)
  40. {
  41.  
  42. System.out.println(toString(a) + " -> " + m(a));
  43. }
  44. }
  45. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] -> 5.0
[1.0, 4.0, 3.0, 2.0] -> 2.5
[1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, -5.0, 100000.0, 1.3, 1.4] -> 1.5