[Java]用递归判断是否为递减数组

No pinyin input method on this machine, so directly paste the code:

 

    /**
     * Judge whether the array is decreased
     * @param array
     * @return
     */
    public boolean isDecrease(int[] array) {
        if (array.length<=1) {
            return true;
        }
        if (array[0]>array[1]) {
            return isDecrease(Arrays.copyOfRange(array, 1, array.length));
        }
        return false;
    }

    public static void main(String[] args) {
        int[] array = new int[]{5,4,6,2,1};
        SessionClass sClass = new SessionClass();
        boolean result = sClass.isDecrease(array);
        System.out.println(result);
    }


 

 

posted @ 2013-03-28 21:21  xinyuyuanm  阅读(492)  评论(0编辑  收藏  举报