Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

2. 前20项之和

public class Text20 { 
    //分析:抓住分子与分母的变化规律。 分子分母都是斐波那契数列,递推公式的得出较为简单
 public static void main(String[] args) { 
  float fenmu=1;float fenzi=2; 
  float sum=fenzi/fenmu; 
  float t=0; 
  for(int i=1;i<20;i++) 
  { 
   t=fenmu+fenzi; 
   fenmu=fenzi; 
   fenzi=t; 
   sum=sum+fenzi/fenmu; 
   System.out.println(sum); 
  } 
 } 
} 

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.