boolean isValidIndex (int [] x, int y) {
if((y>=0) && (y<x.length)) {
return true;
}
else {
return false;
}
}
Write a method called isValidIndex() that takes an array of integers and an index, and returns true if the index is valid for the array. For example, if the array had 10 elements then isValidIndex(array, 9) would return True,but isValidIndex(array, 10) would return False,as would isValidIndex(array, -1).
Here is my code. It works but apparently it can just be one statement. How can I do that?
yto index.