About 81,400 results
Open links in new tab
  1. recursion - Java recursive Fibonacci sequence - Stack Overflow

    The result is stored in int which can handle only a first 48 fibonacci numbers, after this the integer fill minus bit and result is wrong. But you never can run fibonacci(50). The code fibonacci(n - 1) + fibonacci(n - 2) is very inefficient. The problem is that the it …

  2. iteration - Iterative Fibonacci code in Java? - Stack Overflow

    Nov 24, 2015 · the above line of code means that, we are simply adding previous two numbers and saving pointer to it so that we can refer to them. As "fib" will be the previous number and "a" will be previous to previous number and by adding those two number we get the current Fibonacci number and this process continues until the loop ends

  3. In java, how would I find the nth Fibonacci number?

    To find the n'th digit, we need to know the length of the Fibonacci numbers. You can convert int to string using Java's Integer.toString(int) function. Using the string, one can then determine the length of the converted Fibonacci number. EDIT: Removed code b/c likely hwk question

  4. Java Fibonacci Sequence fast method - Stack Overflow

    Oct 4, 2016 · There is a way to calculate Fibonacci numbers instantaneously by using Binet's Formula. Algorithm: function fib(n): root5 = squareroot(5) gr = (1 + root5) / 2 igr = 1 - gr value = (power(gr, n) - power(igr, n)) / root5 // round it to the closest integer since floating // point arithmetic cannot be trusted to give // perfect integer answers.

  5. Fibonacci sequence in Java using for statements - Stack Overflow

    Aug 18, 2013 · Fibonacci series in java is actually quite simple and can be done with just one single for-loop!!!! import java.io.*; class fibonacci{ public static void main() throws NumberFormatException, IOException{ BufferedReader Data=new BufferedReader (new InputStreamReader(System.in)); int a,b,c,d; System.out.println("Upto How many numbers do you want to see?"); d=Integer.parseInt(Data.readLine ...

  6. Java 8 Lambda expressions for solving fibonacci (non recursive way)

    Jun 2, 2015 · The code for the same is given below. boolean checkPrime=n>1 && LongStream.range(2, (long) Math.sqrt(n)).parallel().noneMatch(e->(n)%e==0); In the above code in the noneMatch method we are evaluating with the current value(e) in the range. But for the Fibonacci problem, we requires previous two values. How can we make it happen?

  7. java - fibonacci series - recursive summation - Stack Overflow

    Ok, I initially wrote a simple code to return the Fibonacci number from the series based on the user input.. n=5 will produce

  8. What is a non recursive solution for Fibonacci-like sequence in Java?

    Feb 3, 2012 · The Fibonacci series sequence of numbers starts as: 0,1,1,2,3,5,8,13,21,34,55.... this can be defined by simple recurrence relation F(n)=F(n-1)+F(n-2) for n>1 and two initial conditions, F(0)=1 and F(1)=1. Algorithm Fibonacci //Computes the nth Fibonacci number //Input: A non-negative integer //Output: The nth Fibonacci number. 1.

  9. java - Fibonacci Sequence : Sum of all numbers - Stack Overflow

    I am new to Java and this is what I have to do: The sequence goes as follows: 1, 1, 2, 3, 5, 8, 13, 21, .... Etc. The next number in the sequence is the sum of the previous 2 number ...

  10. Fibonacci Series using Dynamic Programming - Stack Overflow

    Jun 17, 2016 · // Fibonacci Series using Dynamic Programming class fibonacci { static int fib(int n) { /* Declare an array to store Fibonacci numbers. */ int f[] = new int[n+1]; int i; /* 0th and 1st number of the series are 0 and 1*/ f[0] = 0; f[1] = 1; for (i = 2; i <= n; i++) { /* Add the previous 2 numbers in the series and store it */ f[i] = f[i-1] + f[i ...

Refresh