Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Fibonacci {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int f1 = 1;
- int f2 = 1;
- for (int i = 0; i < n - 1 ; i++) {
- int temp = f1 + f2;
- f1 = f2;
- f2 = temp;
- }
- System.out.println(f2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment