Question
Write methods, isAscending and IsDescending , in class OrderChecker , to check whether the elements of a passed in integer array are in ascending and
Write methods, isAscending and IsDescending, in class OrderChecker, to check whether the elements of a passed in integer array are in ascending and descending order respectively. Each method should report true or false.
Your method should be callable in the following manner:
int[] myArray = new int[10];
myArray[0] = 1;
myArray[1] = 2;
myArray[2] = 3;
myArray[3] = 4;
myArray[4] = 5;
if ( OrderChecker checker.isAscending(myArray) ) {
System.out.println(array list is in ascending order);
} else {
System.out.println(array list is not in ascending order);
}
if ( OrderChecker checker.isDescending(myArray) ) {
System.out.println(array list is in descending order);
} else {
System.out.println(array list is not in descending order);
}
In addition to the above, your program should echo the contents of the array before your output of whether it is ascending or descending. For example,
The array: 1, 2, 3, 4, 5 is in ascending order
Make sure you program shows output for multiple invocations of your methods with different array contents. You want to show that your program works for different input.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started