Sunday, November 22, 2015

JAVA FIBONACCI SERIES

1package program;
 2import java.io.*;
 3class fibonacci
 4 {
 5publicvoidfb(int range)
 6     {
 7int first=1,second=-1,fibonacci=0;
 8System.out.println("range of term for fibonacci series"+range);
 9
10for (inti=0;i<range;i++)
11         {
12                 fibonacci=first+second;
13                 second=first;
14                 first=fibonacci;       
15
16System.out.print(""+fibonacci);
17         }
18
19     }
20 }
21publicclassfibo
22 {
23publicstaticvoid main (String args[]) throwsIOException
24  {
25int r;
26InputStreamReader input=newInputStreamReader(System.in);
27BufferedReaderbr=newBufferedReader(input);
28System.out.println("enter number: ");
29      r=Integer.parseInt(br.readLine());
30System.out.println("input number: "+r);
31      fibonacci obj=newfibonacci();
32obj.fb(r);
33  }
34 }
35

36
Output
run:
enter number:
10
input number: 10
range of term for fibonacci series10

 0 1 1 2 3 5 8 13 21 34

No comments:

Post a Comment

JAC Board Computer || IIT 2025 || Introductory Information Technology || Class 10 || Practical Examination 2025

Marks Division HOE 30 Marks IT Application Report File 20 Marks Viva - Voce 10 Marks 1) Write an HTML code to generate a web p...