Java Number Range Create range(int from, int to)

Here you can find the source of range(int from, int to)

Description

range

License

Open Source License

Declaration

public static long[] range(int from, int to) 

Method Source Code

//package com.java2s;
/*/*w w  w .  ja va2s.  com*/
 * Copyright (c) 2016. Sten Martinez
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

public class Main {
    public static long[] range(int from, int to) {
        if (to < from) {
            throw new IllegalArgumentException(
                    String.format("to argument %s is less than from argument %s", to, from));
        }
        long[] array = new long[to - from + 1];
        int i = 0;
        for (int j = from; j <= to; j++) {
            array[i] = j;
            i++;
        }

        return array;
    }

    public static long[] range(long from, long to) {
        if (to < from) {
            throw new IllegalArgumentException(
                    String.format("to argument %s is less than from argument %s", to, from));
        }
        long[] array = new long[(int) (to - from + 1)];
        int i = 0;
        for (long j = from; j <= to; j++) {
            array[i] = j;
            i++;
        }

        return array;
    }
}

Related

  1. range(final int max)
  2. range(float number, float value, float range)
  3. range(int begin, int end)
  4. range(int end)
  5. range(int excludedEnd)
  6. range(int from, int to)
  7. range(int from, int to)
  8. range(int i, int j)
  9. Range(int k, int from, int end)