fork download
  1. import java.util.Arrays;
  2. class M{
  3. static float[] c(int[] x){
  4. int b = Integer.MIN_VALUE,
  5. a = b-1,
  6. j = 0,
  7. l = x.length;
  8. for(int i : x){
  9. a = i < a ? i : a; // Determine min value of array
  10. b = i > b ? i : b; // Determine max value of array
  11. }
  12. float[] r = new float[l];
  13. for(; j < l; r[j] = (x[j++] - a) * 1f / (b-a));
  14. return r;
  15. }
  16.  
  17. public static void main(String[] a){
  18. System.out.println(Arrays.toString(c(new int[]{ 5, -20, 30 })));
  19. System.out.println(Arrays.toString(c(new int[]{ 1, 2, 3, 4, 5 })));
  20. System.out.println(Arrays.toString(c(new int[]{ 0, 5, 100, 400 })));
  21. }
  22. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
[0.5, 0.0, 1.0]
[0.0, 0.25, 0.5, 0.75, 1.0]
[0.0, 0.0125, 0.25, 1.0]