Back to the Web Developer's Journal Main Page
internet.com
side nav bar
Java & JavaScript Discussion Group

We have recently moved our discussion groups to new and better software. The old messages are archived here but you should probably check out the new ones.

WDJ Mailing Lists
Discussion Groups Book Reviews Software Reviews Download Web Tools

Re: How to develop Fibonacci Sequence JAVA program

From:
Category: Category 1
Date: 30 Sep 1998
Time: 16:18:40
Remote Name: 198.64.48.189

Comments

Here is the code for that. Take it into consideration. Thanks.

//Fibonacci Sequence

package fibonacci; import java.lang.*; import java.io.*;

class Fibonacci { public static void main(String args[]) throws IOException

{ DataInputStream input = new DataInputStream(System.in); //Specify input data

int lo=0,hi = 1; //Specify the first two numbers int a,b,c; String str; System.out.println("Enter the number of Fibonacci sequence. Type 0 in order to quit : "); //* Read input and check 0 to quit the program

str = input.readLine(); //Take input as string b = Integer.parseInt(str); //Change string to int if (b == 0) { System.out.println("Quit Program "); c=System.in.read(); //Pause to check output } else {

System.out.println("Fibonacci Sequence:"); System.out.print(lo); //Print the first number for (a=0;a<b-1;a++) {

System.out.print(","+hi); //Print the next number hi = lo + hi; // New hi lo = hi - lo; // New lo } c=System.in.read(); //Pause to check output } } }

Sadly, neither Web Developer's Journal, Markland Communities, Inc., Paige Turner nor anyone else associated with sponsoring these discussion groups can in any way be held responsible for any advice given here. The great unwashed masses of the public Internet hang out here and freely offer advice to all who seek it and some who don't. Take any advice received here with the proverbial grain of salt.
Last changed: November 04, 1998

Back to the Web Developer's Journal
Contact WDJ   •    Suits!   •    Propheads!   •    Ponytails!
Discuss   •    Subscribe   •    Search