Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    /**
     * <p>
     * Reverses the order of the given array.
     * </p>
     * <p>
     * This method does nothing for a {@code null} input array.
     * </p>
     * 
     * @param array the array to reverse, may be {@code null}
     */
    public static void reverse(final int[] array) {
        if (array == null) {
            return;
        }
        reverse(array, 0, array.length);
    }

    /**
     * <p>
     * Reverses the order of the given array in the given range.
     * </p>
     * <p>
     * This method does nothing for a {@code null} input array.
     * </p>
     * 
     * @param array the array to reverse, may be {@code null}
     * @param startIndexInclusive the starting index. Undervalue (&lt;0) is
     *            promoted to 0, overvalue (&gt;array.length) results in no
     *            change.
     * @param endIndexExclusive elements up to endIndex-1 are reversed in the
     *            array. Undervalue (&lt; start index) results in no change.
     *            Overvalue (&gt;array.length) is demoted to array length.
     * @since 3.2
     */
    public static void reverse(final int[] array, int startIndexInclusive, int endIndexExclusive) {
        if (array == null) {
            return;
        }
        int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
        int j = Math.min(array.length, endIndexExclusive) - 1;
        int tmp;
        while (j > i) {
            tmp = array[j];
            array[j] = array[i];
            array[i] = tmp;
            j--;
            i++;
        }
    }
}