Horje
Code for fibonacci numbers using For loop in Java Code Example
Code for fibonacci numbers using For loop in Java
import java.util.*;
public class fibonacci{
    public static void main(String args[]){
        int n,i;
        Scanner sc= new Scanner(System.in);
        n=sc.nextInt();
        sc.close();
        int values[]=new int[n]; // space O(N) used
        values[0]=0;
        values[1]=1;
        for(i=2;i<n;i++)values[i]=values[i-1]+values[i-2]; // single traversal O(N)
        System.out.println("The nth fibonacci number is "+values[n-1]);
    }
}




Java

Related
react-cheat-sheet Code Example react-cheat-sheet Code Example
application properties for using H2 in-memory-DB Code Example application properties for using H2 in-memory-DB Code Example
writeToFileAsync java Code Example writeToFileAsync java Code Example
arc() method from the processing library Code Example arc() method from the processing library Code Example
illegal expression Code Example illegal expression Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10