Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.util.Scanner;
- public class MainBigInts {
- private static BigInteger fibonacci2(int n) {
- BigInteger a = new BigInteger("2");
- BigInteger b = new BigInteger("1");
- BigInteger suma = new BigInteger("0");
- BigInteger temp = new BigInteger("0");
- if (n == 0) {
- return BigInteger.valueOf(1);
- } else {
- if (n == 1) {
- return BigInteger.valueOf(2);
- } else {
- for (int i = 2; i <= n; i++) {
- temp = a;
- a = a.add(b);
- b = temp;
- }
- }
- }
- return a;
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- do {
- System.out.print("Dana: ");
- int a = scanner.nextInt();
- System.out.println(fibonacci2(a));
- } while (true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement