توضح هذه المقالة في شكل أمثلة كيفية تنفيذ Java لتسلسل فيبوناتشي استنادًا إلى أعداد صحيحة عالية الدقة ومشاركتها معك كمرجع لك. الطرق المحددة هي كما يلي:
package com.java.learning.recursion;import java.math.*;public class MainClass { public static void main(String args[]){ for(int i = 0; i < 100; i++){ f(i+1) } } public static BigInteger f(long n){ if(n <= 2){ return new BigInteger("1" }else{ BigInteger n1 = new BigInteger("1"); BigInteger n2 = new BigInteger("1"); BigInteger temp = new BigInteger("0"); for(long i = 0; i < n -2; i++){ temp = n1.add (n2); n1 = n2 = temp; } System.out.println("العنصر " + n + " هو: " + n2); } }}
آمل أن تكون هذه المقالة مفيدة لبرمجة جافا للجميع.