Java Array Length Get length(int[][] instance, int u)

Here you can find the source of length(int[][] instance, int u)

Description

length

License

Open Source License

Declaration

public static double length(int[][] instance, int u) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double length(int[][] instance, int u) {

        double length = 0;
        int numberOfMachines = instance.length;

        int middle = (numberOfMachines / 2) + 1;
        int var = 1;
        boolean useTheSameValue = numberOfMachines % 2 == 0;

        for (int m = numberOfMachines; m > 0; m--) {

            if (m >= middle) { // decrease

                var -= 2;

                length = length + (numberOfMachines - var)
                        * instance[m - 1][u];

            } else { // increase

                if (!useTheSameValue) { // when is a par we need to keep the same value
                    var += 2;
                } else {
                    useTheSameValue = false;
                }/*from ww  w . ja  v a 2 s . c  o  m*/

                length = length - (numberOfMachines - var)
                        * instance[m - 1][u];
            }
        }

        return length;
    }
}

Related

  1. length(final double[] a)
  2. length(final Object[] array)
  3. length(final T[]... arrays)
  4. length(float[] color)
  5. length(int[] tail)
  6. length(long[] v)
  7. length(Object anArray[])
  8. length(Object[] array)
  9. length(Object[] array)