From 776c3c615d2c48eadadf0605b29475759a3fa09c Mon Sep 17 00:00:00 2001 From: Brunda M Bharadwaj <49773125+brundambharadwaj9@users.noreply.github.com> Date: Sun, 10 Oct 2021 11:13:28 +0530 Subject: [PATCH] Rename FibToN.java to FibbonaciSeries.java (#2498) --- Others/{FibToN.java => FibbonaciSeries.java} | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) rename Others/{FibToN.java => FibbonaciSeries.java} (69%) diff --git a/Others/FibToN.java b/Others/FibbonaciSeries.java similarity index 69% rename from Others/FibToN.java rename to Others/FibbonaciSeries.java index 479e89572..076cac53c 100644 --- a/Others/FibToN.java +++ b/Others/FibbonaciSeries.java @@ -9,20 +9,19 @@ import java.util.Scanner; *
Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21,... * *
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) { - // take input - Scanner scn = new Scanner(System.in); - int N = scn.nextInt(); - // print all Fibonacci numbers that are smaller than your given input N + // Get input from the user + Scanner scan = new Scanner(System.in); + int n = scan.nextInt(); int first = 0, second = 1; - scn.close(); - while (first <= N) { + scan.close(); + while (first <= n) { // print first fibo 0 then add second fibo into it while updating second as well - System.out.println(first); - int next = first + second; first = second; second = next;