Java Number Range Create range(int excludedEnd)

Here you can find the source of range(int excludedEnd)

Description

range

License

Apache License

Declaration

public static int[] range(int excludedEnd) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static int[] range(int excludedEnd) {
        return range(0, excludedEnd, 1);
    }/*  ww w . j a  va  2  s. c om*/

    public static int[] range(int includedStart, int excludedEnd) {
        return range(includedStart, excludedEnd, 1);
    }

    public static int[] range(int includedStart, int excludedEnd, int step) {
        if (includedStart > excludedEnd) {
            int tmp = includedStart;
            includedStart = excludedEnd;
            excludedEnd = tmp;
        }

        if (step <= 0) {
            step = 1;
        }

        int deviation = excludedEnd - includedStart;
        int length = deviation / step;
        if (deviation % step != 0) {
            length += 1;
        }
        int[] range = new int[length];
        for (int i = 0; i < length; i++) {
            range[i] = includedStart;
            includedStart += step;
        }
        return range;
    }
}

Related

  1. range(double[] vals)
  2. range(final int max)
  3. range(float number, float value, float range)
  4. range(int begin, int end)
  5. range(int end)
  6. range(int from, int to)
  7. range(int from, int to)
  8. range(int from, int to)
  9. range(int i, int j)