Check if an array is sorted, return true or false

前端 未结 13 1990
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 06:03

I am writing an easy program the just returns true if an array is sorted else false and I keep getting an exception in eclipse and I just can\'t figure out why. I was wonder

13条回答
  •  醉酒成梦
    2020-11-30 06:33

    public static boolean isSorted(int[] a)
    {  
        for ( int i = 0; i < a.length - 1 ; i++ ) {
            if ( a[i] > a[i+1] )
              return false;
        }
        return true;
    }
    

    This function checks whether the array is in Ascending order or not.

提交回复
热议问题