import java.util.*;
public class MyClass {
public static List<Integer> fibonacci_numbers(Integer[] arr) {
Integer max = Collections.max(Arrays.asList(arr));
Integer a = 0, b = 1;
List<Integer> fib = new ArrayList<Integer>();
List<Integer> arr_fib = new ArrayList<Integer>();
fib.add(a);
do {
fib.add(b);
int c = a + b;
a = b;
b = c;
} while (b <= max);
for (Integer i = 0; i < arr.length; i++) {
if (fib.contains(arr[i])) {
arr_fib.add(arr[i]);
}
}
return arr_fib;
}
public static void main(String args[]) {
// 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181
Integer[] arr = {9, 1, 31, 12, 13, 3, 89, 100, 233, 4, 144, 99};
List<Integer> result = new ArrayList<Integer>();
result = fibonacci_numbers(arr);
System.out.println(result);
}
}
/*
run:
[1, 13, 3, 89, 233, 144]
*/