Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean isAlwaysIncreasingOrDecreasing(int[] sequence) {
- //check if decreasing
- int previous = arr[0];
- boolean decreasing = true;
- for(int i = 1; i < arr.length; i++) {
- if(previous < arr[i]) {
- decreasing = false;
- break;
- }
- previous = arr[i];
- }
- //check if increasing
- int previous = arr[0];
- boolean increasing = true;
- for(int i = 1; i < arr.length; i++) {
- if(previous > arr[i]) {
- increasing = false;
- break;
- }
- previous = arr[i];
- }
- //return true if always increasing or decreasing
- if(decreasing || increasing) {
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement