Java Mathematical Induction method of non-recursive Fibonacci sequence _java

Source: Internet
Author: User
Tags int size

This paper illustrates the method of recursive Fibonacci sequence in Java mathematical induction. Share to everyone for your reference. Specifically as follows:

The maximum value that an integer can represent is
2147483647
About 2.14 billion, the overflow is not considered here (it overflows when size is 983)!

Import java.util.List;
Import java.util.ArrayList;
/**
 * @author Jxqlovejava
 * Fibonacci Series/Public
class Fibonacci {public
 static list<integer> Fibonacci (int size) throws Exception {
  int-i = 0;
  int second = 1;
  list<integer> result = new arraylist<integer> ();
  Result.add (a);
  Result.add (second);
  if (Size < 0) {
   throw new Exception ("illegal argument!");
  }
  else if (size <= 2) {return
   result.sublist (0, size);
  }
  int next;
  int count = 2; The number of elements that are currently being deduced while
  (count++ < size) {//fib (0) and FIB (1) Recursively other elements
   next = i + second;
   i = second;
   Second = next;
   Result.add (next);
  return result;
 }
 public static void Main (string[] args) throws Exception {
  list<integer> Fibarray = Fibonacci (a);
  for (int i:fibarray) {
   System.out.print (i + "\ t");}}


I hope this article will help you with your Java programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.