/**
* @Order checking
*/
public static void main(String[] args) {
int[] intArray = { 1, 3, 5, 6, 7, 8, 11, 13, 15, 4, 17, 19, 21, 23 };
for (int i = 0; i < intArray.length - 1; i++) {
if (intArray[i] > intArray[i + 1]) {
System.out
.println("Ascending order of the list breaks at index =>> "
+ (i + 1) + " and the element is =>> "
+ intArray[i + 1]);
}
}
}
}
OUTPUT1:
Ascending order of the list breaks at index =>> 9 and the element is =>> 4
2)To find where Descending order is breaking
public class CheckDscList {
/**
* @CheckDcsList
*/
public static void main(String[] args) {
int[] intArray = { 23,21,19,18,17,15,4,12,10,8,7,5,3,2 };
for (int i = 0; i < intArray.length - 1; i++) {
if (intArray[i] < intArray[i + 1]) {
System.out
.println("Descending order of the list breaks at index =>> "
+ (i) + " and the element is =>> "
+ intArray[i]);
}
}
}
}
OUTPUT2:
Descending order of the list breaks at index =>> 6 and the element is =>> 4
No comments:
Post a Comment