How to determine the fibonaci number up to nth term in java

Monday, March 16, 2009

import java.io.*; class a { public static void main(String args[])throws IOException { BufferedReader ob=new BufferedReader (new InputStreamReader(System.in)); String a; int b; System.out.printf("Enter a number:"); a=ob.readLine(); b=Integer.parseInt(a); System.out.printf("The fibonaci number up to %d term ",b); int m=1;int n =1; System.out.printf("%d %d ",m,n); for(int i=1;i<=b-2;i++) { int s=m+n; n=m;m=s;System.out.printf("%d ",s); } System.out.println(""); } }

0 comments:

Visitors

PlugIn.ws - Free Hit Counter, Web Site Statistics, Traffic Analysis

  © Blogger template Leaving by Ourblogtemplates.com 2008

Back to TOP