Does anyone knows how to write Fibonacci program in java using buffered class
butterflyqueen:
Someome please help me
Answers
Answered by
5
hey!!
here is ur answer!!
========================
A program is here to print the Fibonacci series 0,1,2,3,4,5......n terms....
class Xyz
static void fibonnaci(int n)
{
int a = 0;
int b = 1;
int c;
System.out.println(a + " " + b);
int i = 3;
while(i<=n)
{
c= a+ b;
System.out.println(" "+c);
a = b;
b = c;
}
}
}
==========================================================
here,
in fibonacci series,
first we take three interger terms in which first one will be 0 and second one will be 1....and the third one will be remains without value.....
now we print the statement and take another another value of integer type for showing the value of n (no of terms)
than we use while statement as we khow in fibonacci number the third term will equal to the sum of another two i.e c = a+b...
and in fibonacci the first term is equal to the second term and second term is equal to the first term...
example = 111,555,888, etc....
Hope this helps u!!
here is ur answer!!
========================
A program is here to print the Fibonacci series 0,1,2,3,4,5......n terms....
class Xyz
static void fibonnaci(int n)
{
int a = 0;
int b = 1;
int c;
System.out.println(a + " " + b);
int i = 3;
while(i<=n)
{
c= a+ b;
System.out.println(" "+c);
a = b;
b = c;
}
}
}
==========================================================
here,
in fibonacci series,
first we take three interger terms in which first one will be 0 and second one will be 1....and the third one will be remains without value.....
now we print the statement and take another another value of integer type for showing the value of n (no of terms)
than we use while statement as we khow in fibonacci number the third term will equal to the sum of another two i.e c = a+b...
and in fibonacci the first term is equal to the second term and second term is equal to the first term...
example = 111,555,888, etc....
Hope this helps u!!
Answered by
6
import java.io.*;
class Brainly
{
public static void main(String args[]) throws IOException
{
System.out.println("Enter the number of elements to be read: ");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(br. readLine());
int b = 0, c = 1, d;
System.out.println("The series is: ");
for(int i = 0; i<a; i++)
{
d=b+c;
b=c;
c=d;
System.out.println(b);
}
}
}
Hope this helps!
class Brainly
{
public static void main(String args[]) throws IOException
{
System.out.println("Enter the number of elements to be read: ");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(br. readLine());
int b = 0, c = 1, d;
System.out.println("The series is: ");
for(int i = 0; i<a; i++)
{
d=b+c;
b=c;
c=d;
System.out.println(b);
}
}
}
Hope this helps!
Similar questions