I am very new to Java, sorry if the question is too simple. I am trying to evaluate whether an array is part of the fibonacci sequence. I do not know how to return "true" value when the whole "for" loop does not break. Any ideas? Thank you in advance! This is what I have for now:
public boolean checkFibb(ArrayList<Integer> array1) {
int i;
int fibb;
if (array1.size() < 3) {
System.out.println("Your array is too short!");
} else {
for (i = 0; i <= array1.size() - 2; i++) {
fibb = array1.get(i + 2) - (array1.get(i + 1) + array1.get(i));
if (fibb != 0) {
System.out.println("Elements are not part of the Fibonacci sequence.");
break;
} else {
System.out.println("Elements are part of the Fibonacci sequence.");
}
}
}
return true;
}
break;inside the loop, doreturn false;