Task is to find and return non-consecutive number. What i do: 1. If found, return it 2. If not found and it isn't last number, go further 3. If not found and it is last number, return null
But after last return java wants me another return, and i don't get why. Can you help me and explain this error please?
public class Program
{
static Integer find(final int[] array) {
for (int i=0; i<array.length; i++) {
if (array[i+1] != (array[i] + 1)) {
return array[i+1];
} else if (array[i+1] != array[array.length - 1]){
continue;
} else {
return null;
}
}
}
public static void main(String[] args) {
find(new int[] {1,2,3,4,6,7,8});
}
}
Aucun commentaire:
Enregistrer un commentaire