Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Fibonacci Series Program. in java

//Fibonacci Series using Recursion
class fibonacci
{
    static int fib(int n)
    {
    if (n <= 1)
       return n;
    return fib(n-1) + fib(n-2);
    }
      
    public static void main (String args[])
    {
    int n = 9;
    System.out.println(fib(n));
    }
}
Comment

Fibonacci Series in Java

//Iterative Fibonacci series program in Java

class Fibonacci{  
public static void main(String args[])  
{   
//Considering the first two numbers as 0 and 1 
 int num1=0,num2=1,num3,i,count=10;  
//Count=10 means that only the first 10 fibonacci numbers will be displayed  
 System.out.print(num1+" "+num2);
//printing 0 and 1    
 for(i=2;i<count;++i)  
//looping is initiated from 2 as 0 and 1 are already printed  
 {    
  num3=num1+num2;    
  System.out.print(" "+num3);    
  num1=num2;    
  num2=num3;    
 }    
}}  
Comment

java programme for fibonnaci series

class Main {
  public static void main(String[] args) {

    int n = 10, firstTerm = 0, secondTerm = 1;
    System.out.println("Fibonacci Series till " + n + " terms:");

    for (int i = 1; i <= n; ++i) {
      System.out.print(firstTerm + ", ");

      // compute the next term
      int nextTerm = firstTerm + secondTerm;
      firstTerm = secondTerm;
      secondTerm = nextTerm;
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to do stuff with a scoreboard minecraft 
Java :: thymeleaf string not equal 
Java :: event api spigot 
Java :: print * pattern in java 
Java :: how to divide two ints and get a double java 
Java :: java logger error 
Java :: How to perform a breadth first search through a binary tree, in Java? 
Java :: java create arraylist 
Java :: java get sub array 
Java :: String by byte array in java 
Java :: reading csv file in java 
Java :: how to enable cors request on springboot application 
Java :: java insert into arraylist 
Java :: android date time 
Java :: RecyclerView: No layout manager attached; skipping layout 
Java :: pass list to intent in android java 
Java :: 2d arraylist in java 
Java :: java get file from url 
Java :: java indexof array 
Java :: java replaceall regex 
Java :: split string into int array 
Java :: set java home sdk macbook 
Java :: select photo from camera android 
Java :: random numbers java 
Java :: java loop 
Java :: frequency of each element from list in java 
Java :: java srting array to string 
Java :: java get bigger int 
Java :: reverse a integer in java 
Java :: next greater permutation leetcode 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =