Homework Fibonacci Numbers
package Hw5;/**
*
9224205 江昇祐
*
*
ibonacci numbers.
List the first 100 numbers and the ratio of
a number to its previous number.
*
*
Copyright: Copyright (c) 2006
*
*
CYCUIE
*
*/
public class fibonacci {
public static void main(String[] args) {
double firstNumber = 0;
double secondNumber = 1 ;
double thirdNumber = 0 ;
double ratio = 0 ;
for (int i = 2 ; i<100; i++)
{
if(i==2){
System.out.println("f0 = " + firstNumber+"the ratio =" + ratio);
System.out.println("f1 = " + secondNumber+"the ratio =" + ratio);
}
thirdNumber= firstNumber+secondNumber ;
ratio = thirdNumber/secondNumber;
System.out.println("f"+i+" = "+thirdNumber+ "the ratio =" + ratio);
firstNumber = secondNumber;
secondNumber=thirdNumber ;
}
}
}
0 Comments:
張貼留言
<< Home