Computer Science, asked by KoyenaKundu15, 1 month ago

write a Java program using void function (int) to create a Fibonacci Series up to 30 terms.​

Answers

Answered by anindyaadhikari13
4

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Java.

import java.util.Scanner;

public class Brainly{

   static void function(){

       int a=1,b=0,c=0,i;

       for(i=1;i<=30;i++){

           System.out.print(c+" ");

           c=a+b;

           a=b;

           b=c;

       }

   }

   public static void main(String s[]){

       System.out.println("The first 30 terms of the fibonacci series are: ");

       function();

   }

}

\textsf{\large{\underline{Explanation}:}}

  • A method function() is created which displays the first thirty terms of the Fibonacci series. Fibonacci series is a series in which the first two terms are 0 and 1 and the nth term is equal to the sum of its previous two terms.
  • The function is then called inside main() method so as to display the series of Fibonacci numbers.

See the attachment for output.

Attachments:

anindyaadhikari13: Thanks for the brainliest!
Similar questions