Skip to main content

Featured

Mini Calculator in Python

                 Calculator Using Python                     num1=10                                                                                                                                         num2 =20                         ans1 = num1 + num2                     print ( "Th...

Fibonacci Series using JAVA

Here is the Code in JAVA :-

To find the Fibonacci series  using Bufferedreader class.

 

 EXPLANATION :-

In this we have taken  Variable z in which we will take the value upto what we want to get the Fibonacci Series.

Then there are two variables num1 and num2 having value 0 and 1 ,respectively.

 

And then we will Apply all the rules that are used to find the Fibonacci series.

in Fibonacci series we add the previous two numbers to get new number in the list and using for lof we can find whole Fibonacci series.

 

CODE:-

 

 

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;


public class aman2 {
public static void main(String[] args) throws IOException {
int num1 = 0;
int num2 = 1;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a string");
int z = Integer.parseInt(br.readLine());
int sum = 0;
System.out.println(num1);
System.out.println(num2);
for (int i = 0; i <= z; i++) {
sum = num1 + num2;
System.out.println(sum);
num1 = num2;
num2 = sum;
}
}

}

 

 

GITHUB:- https://github.com/Amanlath1/Learning/blob/main/fibonacci.java



Comments

Popular Posts