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

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 :: java try...catch 
Java :: java infinite for loop 
Java :: how to make window in java 
Java :: null java 
Java :: log messages not printing in springboot using org.slf4j.Logger; 
Java :: Simple For Loop Java Example 
Java :: Could not resolve project :app 
Java :: is c# similar to java 
Java :: java variable 
Java :: multiple spinner android 
Java :: get field name java 
Java :: regex java 
Java :: hash map java 
Java :: Java long Keyword 
Java :: hashtable in java 
Java :: double to int 
Java :: maths trivia in java 
Java :: streams in java 
Java :: get string size 
Java :: binary tree traversal 
Java :: java hex to rgb 
Java :: spring swagger ui login oauth2 
Java :: run jar file with different jre 
Java :: arraylist methods in java 
Java :: java print array of objects 
Java :: android videoview not smooth for mp4 
Java :: android activity set action bar options 
Java :: h2 database spring boot create table application.properties 
Java :: java method overloading 
Java :: What is builder tool 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =