In: Computer Science
Create a method: Public Static boolean isSubArray489(int[] intArray)
This method has an array of integers as its input parameter, we'll say that a SubArray 9,8,7is that three integers, 9,8,7values appearing decreasing order one by one in the array. Return true if the array does contain any SubArray “987” Notice that any 3 integers that presenting a decreasing by one order must return True. (987, 876,765,654, 543, 432,321, 210 are all True)
Call this method in your main function, and pass in arrays like following:
public class SubArray {
public static boolean isSubArray489(int[] intArray) {
for(int i:intArray) {
if(isItValid(i))
return true;
}
return false;
}
private static boolean isItValid(int n) {
int a=n%10;
n=n/10;
int b=n %10;
n=n/10;
int c=n;
return (c-b==1 && b-a==1 && a<b && b<c);
}
public static void main(String[] args) {
int arr[]= {987, 876,765,654, 543, 432,321, 210};
System.out.println(isSubArray489(arr));
int arr1[]= {123,436,534,651,455};
System.out.println(isSubArray489(arr1));
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME