Advertisement
hackmate

Untitled

May 19th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class MainBigInts {
  5. private static BigInteger fibonacci2(int n) {
  6. BigInteger a = new BigInteger("2");
  7. BigInteger b = new BigInteger("1");
  8. BigInteger suma = new BigInteger("0");
  9. BigInteger temp = new BigInteger("0");
  10.  
  11.  
  12. if (n == 0) {
  13. return BigInteger.valueOf(1);
  14. } else {
  15. if (n == 1) {
  16. return BigInteger.valueOf(2);
  17. } else {
  18. for (int i = 2; i <= n; i++) {
  19. temp = a;
  20. a = a.add(b);
  21. b = temp;
  22. }
  23. }
  24. }
  25. return a;
  26. }
  27.  
  28. public static void main(String[] args) {
  29.  
  30. Scanner scanner = new Scanner(System.in);
  31. do {
  32. System.out.print("Dana: ");
  33. int a = scanner.nextInt();
  34. System.out.println(fibonacci2(a));
  35. } while (true);
  36.  
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement