11 September 2018

Java Program to generate nth term in Fibonacci series

//Program to generate nth term in Fibonacci series
import java.util.*;
class nfibo
     {
   public static void main(String args[])
      {
    int f1=1,f2=1,f3=0,n,i;
    System.out.print("enter the term you want to find : ");
    Scanner obj = new Scanner(System.in);
    n=obj.nextInt();
    if(n==1)
      System.out.println(f1);
    else if(n==2)
       System.out.println(f2);
    else if(n>=3)
         {
        for(i=3;i<=n;i++)
            {
            f3=f1+f2;
            f1=f2;
            f2=f3;
            }
        System.out.println(f3);
         }
        }
      }
A similar program to this
 Java Program to generate Fibonacci series

No comments:

Post a Comment

To convert from Upper case to lowercase(A to a)

//converting from Upper to lower(A to a) import java.util.*; class case { public static void main(String args[]) { System.out.pr...