Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. public static boolean isAlwaysIncreasingOrDecreasing(int[] sequence) {
  2. //check if decreasing
  3. int previous = arr[0];
  4. boolean decreasing = true;
  5. for(int i = 1; i < arr.length; i++) {
  6. if(previous < arr[i]) {
  7. decreasing = false;
  8. break;
  9. }
  10. previous = arr[i];
  11. }
  12.  
  13. //check if increasing
  14. int previous = arr[0];
  15. boolean increasing = true;
  16. for(int i = 1; i < arr.length; i++) {
  17. if(previous > arr[i]) {
  18. increasing = false;
  19. break;
  20. }
  21. previous = arr[i];
  22. }
  23.  
  24. //return true if always increasing or decreasing
  25. if(decreasing || increasing) {
  26. return false;
  27. }
  28.  
  29. return true;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement