Java Zero Format zeroThrough(int max)

Here you can find the source of zeroThrough(int max)

Description

zero Through

License

Open Source License

Declaration

public static int[] zeroThrough(int max) 

Method Source Code

//package com.java2s;
/*/*w ww. j  a va 2 s. c  o  m*/
 *
 *  Managed Data Structures
 *  Copyright ? 2016 Hewlett Packard Enterprise Development Company LP.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  As an exception, the copyright holders of this Library grant you permission
 *  to (i) compile an Application with the Library, and (ii) distribute the 
 *  Application containing code generated by the Library and added to the 
 *  Application during this compilation process under terms of your choice, 
 *  provided you also meet the terms and conditions of the Application license.
 *
 */

public class Main {
    public static int[] zeroThrough(int max) {
        return ints(0, max, 1);
    }

    public static int[] ints(final int min, final int max, final int step) {
        int n = (max - min) / step + 1;
        if (n < 0) {
            return new int[0];
        }
        int[] array = new int[n];
        int next = min;
        for (int i = 0; i < n; i++) {
            array[i] = next;
            next += step;
        }
        return array;
    }

    public static int[] ints(int min, int max) {
        return ints(min, max, min > max ? -1 : 1);
    }
}

Related

  1. zeros(int size)
  2. zerosInt(int len)
  3. zeroString(int length)
  4. zeroString(int value)
  5. zeroSupply(String value, int len)
  6. zeroToOne(float value, float min, float max)
  7. zeroToOne(long _min, long _max, long _value)
  8. zeroToSpace(String s)
  9. zeroToStr(String fStr, String lStr)