public class Fibonacci {
public static List<Integer> generateFibonacci(int n) {
List<Integer> fibSeries = new List<Integer>();
Integer a = 0, b = 1;
for (Integer i = 0; i < n; i++) {
fibSeries.add(a);
Integer next = a + b;
a = b;
b = next;
}
return fibSeries;
}
}
cHVibGljIGNsYXNzIEZpYm9uYWNjaSB7CgogICAgcHVibGljIHN0YXRpYyBMaXN0PEludGVnZXI+IGdlbmVyYXRlRmlib25hY2NpKGludCBuKSB7CiAgICAgICAgTGlzdDxJbnRlZ2VyPiBmaWJTZXJpZXMgPSBuZXcgTGlzdDxJbnRlZ2VyPigpOwogICAgICAgIEludGVnZXIgYSA9IDAsIGIgPSAxOwogICAgICAgIAogICAgICAgIGZvciAoSW50ZWdlciBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgICAgICBmaWJTZXJpZXMuYWRkKGEpOwogICAgICAgICAgICBJbnRlZ2VyIG5leHQgPSBhICsgYjsKICAgICAgICAgICAgYSA9IGI7CiAgICAgICAgICAgIGIgPSBuZXh0OwogICAgICAgIH0KICAgICAgICAKICAgICAgICByZXR1cm4gZmliU2VyaWVzOwogICAgfQp9Cg==