Fiji Retracement--for Baidu Encyclopedia
Fibonacci series (Fibonacci sequence), also known as the Golden Section series, because the mathematician Leonardo's Fibonacci (Leonardoda Fibonacci) to the rabbit breeding as an example of the introduction, so called "Rabbit series", refers to such a series: 1, 1, 2, 3, 5, 8, 13, 21, 、...... In mathematics, the Fibonacci sequence is defined as follows: F (1) =1,f (2) =1, f (n) =f (n-1) +f (n-2) in the fields of modern physics, quasi-crystal structure, chemistry and so on, the Fibonacci sequence has a direct application, Since 1963, the American Mathematical Council has published a mathematical magazine in the name of the Fibonacci series Quarterly, which is devoted to the research.
Loop implementation
public static void main(String[] args) { // TODO Auto-generated method stub int n=0; Scanner sc=new Scanner(System.in); int x1=1,x2=1; int temp=x1; while(true){ n=sc.nextInt(); x1=1; x2=1; for(int i=1;i<n;i++) { temp=x2; x2=sum(x1,x2); x1=temp; } System.out.println("结果:"+temp); } } public static int sum(int x1,int x2) { return x1+x2; }
Results
Java Loop output Fibonacci sequence