9/22/10



Fibonacci Code - Java

9/22/2010

Java Code for generating fibonacci numbers:

import javax.swing.*;


public class Fibonacci {


 public static void main (String[] args) {


    String inputSequence = "";
    int a = 1, b = 1, sum = 0;
    int sequence= 0;


    inputSequence = JOptionPane.showInputDialog("Enter number of 
                          sequence you want to see: ");


    sequence = Integer.parseInt(inputSequence);


    int i = 1;
    while(i <= sequence){
         System.out.printf("Fib(%d)= %3d\n",i,a);
         sum = a + b;
         a = b;
         b = sum;
         i++;
    }


 System.exit(0);
 }
}



Your thoughts about this post? Leave a commment now.

Posted by

AndyFGo : A place for Pinoy Music News. Lyrics. Music Videos. Pinoy Movie/Foreign Trailers. OPM.

 

© 2013 andyfgo. All rights reserved. Designed by Templateism. Powered by Blogger
Protected by Copyscape DMCA Takedown Notice Violation Search

Back To Top