Java Range rangeDivide(Integer begin, Integer end, Integer divideNum)

Here you can find the source of rangeDivide(Integer begin, Integer end, Integer divideNum)

Description

range Divide

License

Open Source License

Declaration

public static Integer[][] rangeDivide(Integer begin, Integer end, Integer divideNum) 

Method Source Code

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

public class Main {
    public static Integer[][] rangeDivide(Integer begin, Integer end, Integer divideNum) {
        if (begin == null || end == null || begin >= end || divideNum == null || divideNum <= 0) {
            return null;
        }//from  w w w.  j  a  v  a 2 s . c om
        Integer[][] ranges = new Integer[divideNum][2];
        int spread = end - begin;
        for (int i = 1; i < divideNum; i++) {
            ranges[i - 1][0] = spread / divideNum * (i - 1) + begin;
            ranges[i - 1][1] = spread / divideNum * i + begin;
        }
        ranges[divideNum - 1][0] = spread / divideNum * (divideNum - 1) + begin;
        ranges[divideNum - 1][1] = spread + begin;
        return ranges;
    }
}

Related

  1. rangeEquals(byte[] a, int aStart, byte[] b, int bStart, int length)
  2. rangeIncludes(long x, long min, long max)
  3. rangeInteger(Integer num, Integer min, Integer max)
  4. rangeLimit(float value, float min, float max)