Thursday, 16 June 2016

Write a method that returns the nth value of the Fibonacci sequence.

int num = 0;
 int num2 = 1; 
 int fibonacci
for (int i= 0; i< n; i++)
{
    fibonacci = num + num2;
    num = num2;
    num2 = fibonacci;
}
System.out.print(num);


to find the nth, you have to iterate the step n times and only print it when you've finished.


No comments:

Post a Comment

Find Duplicate Characters In String using Java

package com.zia.test; import java.util.HashMap; import java.util.Map; import java.util.Set; public class findDuplicateCharacter { /**...