write a Java program using void function (int) to create a Fibonacci Series up to 30 terms.
Answers
Answered by
4
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();
}
}
- 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
Math,
5 hours ago
Physics,
5 hours ago
Science,
9 hours ago
Social Sciences,
8 months ago
Math,
8 months ago