mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-11 06:04:27 +08:00
Rename FibToN.java to FibbonaciSeries.java (#2498)
This commit is contained in:

committed by
GitHub

parent
f1ec159d85
commit
776c3c615d
@ -9,20 +9,19 @@ import java.util.Scanner;
|
|||||||
* <p>Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21,...
|
* <p>Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21,...
|
||||||
*
|
*
|
||||||
* <p>Source for the explanation: https://en.wikipedia.org/wiki/Fibonacci_number
|
* <p>Source for the explanation: https://en.wikipedia.org/wiki/Fibonacci_number
|
||||||
|
*
|
||||||
|
* Problem Statement: print all Fibonacci numbers that are smaller than your given input N
|
||||||
*/
|
*/
|
||||||
public class FibToN {
|
public class FibbonaciSeries {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// take input
|
// Get input from the user
|
||||||
Scanner scn = new Scanner(System.in);
|
Scanner scan = new Scanner(System.in);
|
||||||
int N = scn.nextInt();
|
int n = scan.nextInt();
|
||||||
// print all Fibonacci numbers that are smaller than your given input N
|
|
||||||
int first = 0, second = 1;
|
int first = 0, second = 1;
|
||||||
scn.close();
|
scan.close();
|
||||||
while (first <= N) {
|
while (first <= n) {
|
||||||
// print first fibo 0 then add second fibo into it while updating second as well
|
// print first fibo 0 then add second fibo into it while updating second as well
|
||||||
|
|
||||||
System.out.println(first);
|
System.out.println(first);
|
||||||
|
|
||||||
int next = first + second;
|
int next = first + second;
|
||||||
first = second;
|
first = second;
|
||||||
second = next;
|
second = next;
|
Reference in New Issue
Block a user