哪位高手帮我解释一下这个是做了一个什么事?
import javax.swing.*;
public class Fibonacci {
public static void main(String[] args){
String input;
int length;
int term1 = 0;
int term2 = 1;
int temp;
input = JOptionPane.showInputDialog("Enter the number of terms to display");
length = Integer.parseInt(input);
for (int i=0; i<length; i++){
if (i==0)
System.out.print(term1 + ", ");
else {
System.out.print(term2 + ", ");
temp = term1;
term1 = term2;
term2 = term2 + temp;
//System.out.print(term2 + ", ");
}//close else
}//close for
}
}
我最不明白的是 temp = term1;
term1 = term2;
term2 = term2 + temp;
为什么要这样写呢? 这样写有什么好处啊?我自己调试了一下 还是不很明白!