|
|
From:
Category: Category 1
Date: 30 Sep 1998
Time: 16:18:40
Remote Name: 198.64.48.189
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 |
|
|
Discuss Subscribe Search |