{"id":74658,"date":"2022-07-05T09:37:02","date_gmt":"2022-07-05T04:07:02","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/"},"modified":"2024-09-12T14:20:04","modified_gmt":"2024-09-12T08:50:04","slug":"fibonacci-series-in-java","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/","title":{"rendered":"Fibonacci Series in Java: 5 ways to print Fibonacci series in Java"},"content":{"rendered":"\n<p>Fibonacci series refers to the series where the following number is the addition of the previous two numbers. The first two numbers of the series are usually 0 and 1.&nbsp;<\/p>\n\n\n\n<p><strong>Example <\/strong><\/p>\n\n\n\n<p>input= 9<\/p>\n\n\n\n<p>output= 0,1,1,2,3,5,8,13,21<\/p>\n\n\n\n<p>Here, the first number is 0 while the second is 1; hence, the next number would be the sum of these two numbers that is 0+1=1. Similarly 1+1=2; 1+2=3, 2+3=5; 3+5=8; 5+8=13; 8+13=21<\/p>\n\n\n\n<p>There are different ways or methods to display the Fibonacci series.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fibonacci-series-in-java-without-using-recursion\"><strong>Fibonacci Series in Java without using recursion<\/strong><\/h2>\n\n\n\n<p>We can avoid the repeated work we performed in recursion by the dynamic programming method.&nbsp;<\/p>\n\n\n\n<p>To perform this, we need first to create an array arr[] of size N. Then, we need to initialize the array as arr[0]=0; arr[1]=1. After this we iterate the value of i from 2 to N, and update the array arr[] as&nbsp;<\/p>\n\n\n\n<p>arr[i]= arr[i-2] + arr[i-1].&nbsp;<\/p>\n\n\n\n<p>Finally, we print the value N.&nbsp;<\/p>\n\n\n\n<p>This syntax is the same as the original syntax of the Fibonacci series the only difference is that we have used an array.&nbsp;<\/p>\n\n\n\n<p><strong>The implementation is illustrated below<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Fibonaccigreatlearning{\npublic static void main(String args&#91;])\n{  \n int n1=0,n2=1,n3,i,count=15;  \n System.out.print(n1+\" \"+n2);\/\/printing 0 and 1  \n  \n for(i=2;i&lt;count;++i)\/\/loop starts from 2 because 0 and 1 are already printed  \n {  \n  n3=n1+n2;  \n  System.out.print(\" \"+n3);  \n  n1=n2;  \n  n2=n3;  \n }  \n\n}}<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 <\/pre>\n\n\n\n<p>In this case, the time complexity and Auxiliary space are the same: O (N).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fibonacci-series-using-recursion-in-java\"><strong>Fibonacci Series using recursion in Java<\/strong><\/h2>\n\n\n\n<p>There are some conditions satisfying which we can use recursion in <a href=\"https:\/\/www.mygreatlearning.com\/blog\/java-tutorial-for-beginners\/\">Java<\/a>.<\/p>\n\n\n\n<p>Firstly we would need the number whose Fibonacci series needs to be calculated&nbsp;<\/p>\n\n\n\n<p>Now recursively iterate the value from N to 1.&nbsp;<\/p>\n\n\n\n<p>There are the following two cases in it:<\/p>\n\n\n\n<p><strong>Base case-<\/strong> here, if the value that is called is less than 1, then the function returns 1&nbsp;<\/p>\n\n\n\n<p><strong>Recursive call- <\/strong>the previous two values are called in case the base case is not met.&nbsp;<\/p>\n\n\n\n<p>The syntax for which is as follows&nbsp;<\/p>\n\n\n\n<p><strong>recursive_function (N-1) + recursive_function (N-2);<\/strong><\/p>\n\n\n\n<p>There is also a term referred to as recursive function; it is called at each recursive call to return the previous two values for the recursive function.<\/p>\n\n\n\n<p><strong>Implementation:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Fibonaccigreatlearning{\n static int n1=0,n2=1,n3=0;  \n static void printFibonacci(int count){  \n    if(count&gt;0){  \n         n3 = n1 + n2;  \n         n1 = n2;  \n         n2 = n3;  \n         System.out.print(\" \"+n3); \n         printFibonacci(count-1);  \n     }  \n }  \n public static void main(String args&#91;]){  \n  int count=20;  \n  System.out.print(n1+\" \"+n2);\/\/printing 0 and 1  \n  printFibonacci(count-2);\/\/n-2 because 2 numbers are already printed \n }\n}<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>-&nbsp;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 <\/pre>\n\n\n\n<p>Here the time complexity and Auxiliary space are O(2^N) and O(1), respectively.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"display-fibonacci-series-using-for-loop\"><strong>Display Fibonacci Series Using For Loop<\/strong><\/h2>\n\n\n\n<p>This loop is the same as that of the while loop. Firstly, we initialize numbers for the first two digits, after which we print the series's first term, hence computing the next term by the formula of Fibonacci. Finally, carry out further by assigning the value of the second term to the first term and the next term to the second term.<\/p>\n\n\n\n<p><strong>Implementation<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class greatlearning{\n  public static void main(String&#91;] args) {\n\n    int n =17 ,firstTerm = 0, secondTerm = 1;\n    System.out.println(\"Fibonacci Series till \" + n + \" terms:\");\n\n    for (int i = 1; i &lt;= n; ++i) {\n      System.out.print(firstTerm + \", \");\n\n      \/\/ compute the next term\n      int nextTerm = firstTerm + secondTerm;\n      firstTerm = secondTerm;\n      secondTerm = nextTerm;\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">Fibanacci Series till 17 terms: \n0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"display-fibonacci-series-using-while-loop\"><strong>Display Fibonacci series using While loop<\/strong><\/h2>\n\n\n\n<p>The while loop is the iterative function where the first and second numbers are 0 and 1, respectively. We print these numbers and then send them to the iterative while loop, where the next number is obtained by adding the previous two numbers. Then simultaneously, we swap the numbers where the first number is the second number and the second number becomes the third.<\/p>\n\n\n\n<p><strong>We can implement the while loop as below <\/strong><\/p>\n\n\n\n<p>\/\/ Java program for the above approach<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Greatlearning {\n\n\t\/\/ Function to print N Fibonacci Number\n\tstatic void Fibonacci(int N)\n\t{\n\t\tint num1 = 0, num2 = 1;\n\n\t\tint counter = 0;\n\n\t\t\/\/ Iterate till counter is N\n\t\twhile (counter &lt; N) {\n\n\t\t\t\/\/ Print the number\n\t\t\tSystem.out.print(num1 + \" \");\n\n\t\t\t\/\/ Swap\n\t\t\tint num3 = num2 + num1;\n\t\t\tnum1 = num2;\n\t\t\tnum2 = num3;\n\t\t\tcounter = counter + 1;\n\t\t}\n\t}\n\n\t\/\/ Driver Code\n\tpublic static void main(String args&#91;])\n\t{\n\t\t\/\/ Given Number N\n\t\tint N = 18;\n\n\t\t\/\/ Function Call\n\t\tFibonacci(N);\n\t}\n}<\/code><\/pre>\n\n\n\n<p><strong>Output <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-cyan-bluish-gray-background-color has-background\">0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1567<\/pre>\n\n\n\n<p>Here the time complexity and auxiliary spaces are O(N) and O(1), respectively.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"display-the-fibonacci-series-up-to-a-given-number\"><strong>Display the Fibonacci series up to a given number<\/strong><\/h2>\n\n\n\n<p>In the previous cases, we defined the number of which we printed the Fibonacci series, but in this case, we print the series up to a number.<\/p>\n\n\n\n<p>We do so by comparing the first number or term with n, and if the first number is proved to be less than n, then the number is printed in the series. If not so, then the series is assumed to be completed.&nbsp;<\/p>\n\n\n\n<p><strong>We can illustrate it as below<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class greatlearning {\n  public static void main(String&#91;] args) {\n\n    int n = 88, firstTerm = 0, secondTerm = 1;\n        \n    System.out.println(\"Fibonacci Series Upto \" + n + \": \");\n    \n    while (firstTerm &lt;= n) {\n      System.out.print(firstTerm + \", \");\n\n      int nextTerm = firstTerm + secondTerm;\n      firstTerm = secondTerm;\n      secondTerm = nextTerm;\n\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Fibonacci series upto 88: \n0, 1,1,2,3,5,8,13,21,34,55,<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>With this, we come to the end of this blog. Embark on a learning adventure like no other with our extensive collection of <a href=\"https:\/\/www.mygreatlearning.com\/academy\" target=\"_blank\" rel=\"noreferrer noopener\">free online courses<\/a>. Whether you're interested in diving into the world of Cybersecurity, mastering the art of Management, exploring the wonders of Cloud Computing, or delving into the intricate realm of IT and Software, we have courses that cater to your interests and goals.<\/p>\n\n\n\n<p>Engaging in the study of Java programming suggests a keen interest in the realm of software development. For those embarking upon this journey with aspirations towards a career in this field, it is recommended to explore the following pages in order to acquire a comprehensive understanding of the development career path:<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter\"><table class=\"has-cyan-bluish-gray-background-color has-background\"><tbody><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/certificates\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses certificates<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/placements\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses placements<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/syllabus\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses syllabus<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/fees\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses fees<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/eligibility\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses eligibility<\/a><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Fibonacci series refers to the series where the following number is the addition of the previous two numbers. The first two numbers of the series are usually 0 and 1.&nbsp; Example input= 9 output= 0,1,1,2,3,5,8,13,21 Here, the first number is 0 while the second is 1; hence, the next number would be the sum of [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":74676,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36826],"content_type":[],"class_list":["post-74658","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-java"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Fibonacci Series in Java: 5 ways to print Fibonacci series in Java<\/title>\n<meta name=\"description\" content=\"Fibonacci Series in Java: Let us look at a few examples of the Fibonacci Series in Java- with Recursion, with For Loop and While Loop.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Fibonacci Series in Java: 5 ways to print Fibonacci series in Java\" \/>\n<meta property=\"og:description\" content=\"Fibonacci Series in Java: Let us look at a few examples of the Fibonacci Series in Java- with Recursion, with For Loop and While Loop.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-05T04:07:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-12T08:50:04+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"869\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/fibonacci-series-in-java\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/fibonacci-series-in-java\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Fibonacci Series in Java: 5 ways to print Fibonacci series in Java\",\"datePublished\":\"2022-07-05T04:07:02+00:00\",\"dateModified\":\"2024-09-12T08:50:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/fibonacci-series-in-java\\\/\"},\"wordCount\":737,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/fibonacci-series-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/fibonacci-1079783_1280.jpg\",\"keywords\":[\"java\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/fibonacci-series-in-java\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/fibonacci-series-in-java\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/fibonacci-series-in-java\\\/\",\"name\":\"Fibonacci Series in Java: 5 ways to print Fibonacci series in Java\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/fibonacci-series-in-java\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/fibonacci-series-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/fibonacci-1079783_1280.jpg\",\"datePublished\":\"2022-07-05T04:07:02+00:00\",\"dateModified\":\"2024-09-12T08:50:04+00:00\",\"description\":\"Fibonacci Series in Java: Let us look at a few examples of the Fibonacci Series in Java- with Recursion, with For Loop and While Loop.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/fibonacci-series-in-java\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/fibonacci-series-in-java\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/fibonacci-series-in-java\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/fibonacci-1079783_1280.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/fibonacci-1079783_1280.jpg\",\"width\":1280,\"height\":869,\"caption\":\"fibonacci series in java\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/fibonacci-series-in-java\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Fibonacci Series in Java: 5 ways to print Fibonacci series in Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Fibonacci Series in Java: 5 ways to print Fibonacci series in Java","description":"Fibonacci Series in Java: Let us look at a few examples of the Fibonacci Series in Java- with Recursion, with For Loop and While Loop.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Fibonacci Series in Java: 5 ways to print Fibonacci series in Java","og_description":"Fibonacci Series in Java: Let us look at a few examples of the Fibonacci Series in Java- with Recursion, with For Loop and While Loop.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2022-07-05T04:07:02+00:00","article_modified_time":"2024-09-12T08:50:04+00:00","og_image":[{"width":1280,"height":869,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Fibonacci Series in Java: 5 ways to print Fibonacci series in Java","datePublished":"2022-07-05T04:07:02+00:00","dateModified":"2024-09-12T08:50:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/"},"wordCount":737,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280.jpg","keywords":["java"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/","url":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/","name":"Fibonacci Series in Java: 5 ways to print Fibonacci series in Java","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280.jpg","datePublished":"2022-07-05T04:07:02+00:00","dateModified":"2024-09-12T08:50:04+00:00","description":"Fibonacci Series in Java: Let us look at a few examples of the Fibonacci Series in Java- with Recursion, with For Loop and While Loop.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280.jpg","width":1280,"height":869,"caption":"fibonacci series in java"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/fibonacci-series-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Fibonacci Series in Java: 5 ways to print Fibonacci series in Java"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280.jpg",1280,869,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280-300x204.jpg",300,204,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280-768x521.jpg",768,521,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280-1024x695.jpg",1024,695,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280.jpg",1280,869,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280.jpg",1280,869,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280-640x853.jpg",640,853,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/fibonacci-1079783_1280-150x102.jpg",150,102,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Fibonacci series refers to the series where the following number is the addition of the previous two numbers. The first two numbers of the series are usually 0 and 1.&nbsp; Example input= 9 output= 0,1,1,2,3,5,8,13,21 Here, the first number is 0 while the second is 1; hence, the next number would be the sum of&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/74658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=74658"}],"version-history":[{"count":15,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/74658\/revisions"}],"predecessor-version":[{"id":104515,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/74658\/revisions\/104515"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/74676"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=74658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=74658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=74658"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=74658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}