We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents dfe5943 + 9b4ae39 commit 4d6e69dCopy full SHA for 4d6e69d
1 file changed
Misc/FibToN.java
@@ -0,0 +1,24 @@
1
+import java.util.Scanner;
2
+
3
+public class FibToN {
4
5
+ public static void main(String[] args) {
6
+ //take input
7
+ Scanner scn = new Scanner(System.in);
8
+ int N = scn.nextInt();
9
+ // print fibonacci sequence less than N
10
+ int first = 0, second = 1;
11
+ //first fibo and second fibonacci are 0 and 1 respectively
12
13
+ while(first <= N){
14
+ //print first fibo 0 then add second fibo into it while updating second as well
15
16
+ System.out.println(first);
17
18
+ int next = first+ second;
19
+ first = second;
20
+ second = next;
21
+ }
22
23
24
+}
0 commit comments