This method is supposed to return true if one of the first 4 elements in the array is a 9. The array length may be less than 4. In my method, for some reason, I keep getting "missing return statement error".
public boolean arrayFront9(int[] nums) {
if (nums.length < 4) {
int counter = 0;
while (counter != nums.length) {
if (nums[counter] == 9) {
return true;
}else{
counter = counter + 1;
}
} if (counter > nums.length) {
return false;
}
}else{
int counter = 0;
while (counter <= 4) {
if (nums[counter] == 9) {
return true;
}else{
counter = counter + 1;
} if (counter > 4) {
return false;
}
}
}
}
`
I understand I have to make sure that no matter what the code has to have some return value, but given the if and else statement, the length of the array is either less than 4 or greater than or equal to 4, so no matter what array is presented it should enter one of these conditionals?