Number at f(93) in fibonacci series has negative value, how?

前端 未结 3 1779
别那么骄傲
别那么骄傲 2020-12-21 04:20

I am trying to printout fibonacci series upto \'N\' numbers. All works as per expectation till f(92) but when I am trying to get the value of f(93), values turns out in nega

3条回答
  •  一向
    一向 (楼主)
    2020-12-21 04:57

    As correctly said in above answers, you've experienced overflow, however with below java 8 code snippet you can print series.

    Stream.iterate(new BigInteger[] {BigInteger.ZERO, BigInteger.ONE}, t -> new BigInteger[] {t[1], t[0].add(t[1])})
            .limit(100)
            .map(t -> t[0])
            .forEach(System.out::println);
    

提交回复
热议问题