Write a java program to find Fibonacci series


Write a java program to find Fibonacci series in java.

Write java code to find Fibonacci series .


1st METHOD -FIND FIBONACCI SERIES

 
 import java.util.Scanner;
class fabonics
{
public static void main(String args[])
{
System.out.println("Enter the no:");
                Scanner a=new Scanner(System.in);
                                int b=a.nextInt();
System.out.println("Fabonics series");
int j=0,k=1,m=0;
System.out.println(j);
System.out.println(k);
while(m<b)
{
m=k+j;
j=k;
k=m;
System.out.println(m);
}
}
}


////////

 
2ND METHOD -FIND FIBONACCI SERIES

import java.io.*;
public class fibonacci_series
{
 public static void main(String[]args)throws IOException
 {
      int range,a=0,b=1,c;
   BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
   System.out.println("Enter the required number of fibonacci series max value:-");
   range = Integer.parseInt(br.readLine());
   System.out.println("Fibonacci series:-");
   for(c=0;c<=range;c=a+b)
   {
       System.out.print(c+" ");
    a=b;
    b=c;
   }
  
 }
}
 

No comments:

Post a Comment