mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-05 16:27:33 +08:00
add FibToN
print all fibonacci till N in O(n)
This commit is contained in:
21
Misc/FibToN
Normal file
21
Misc/FibToN
Normal file
@ -0,0 +1,21 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class FibToN {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scn = new Scanner(System.in);
|
||||
|
||||
int n = scn.nextInt();
|
||||
|
||||
int fn = 0, sn = 1;
|
||||
|
||||
while(fn <= n){
|
||||
System.out.println(fn);
|
||||
|
||||
int next = fn + sn;
|
||||
fn = sn;
|
||||
sn = next;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user