Can somebody explain me this plz

Hi,

I have resolved my task by researching on the Internet but I am having trouble how this mathematics is working.

question is

9. In mathematics, there is a famous sequence of numbers called the Fibonacci sequence after the thirteenth-century Italian mathematician Leonardo Fibonacci. The first two terms in this sequence are 0 and 1, and every subsequent term is the sum of the preceding two. Thus the first several numbers in the Fibonacci sequence are as

follows:

F0 = 0

F1 = 1

F2 = 1 (0 + 1)

F3 = 2 (1 + 1)

F4 = 3 (1 + 2)

F5 = 5 (2 + 3)

F6 = 8 (3 + 5)

Write a program to display the values in this sequence from F0 through F15.

answer is :

-----------------------------------------------xx-------------------

import acm.program.*;

public class fibbonaci extends ConsoleProgram {

public static int fib(int n) {

int prev1=0, prev2=1;

for(int i=0; i<n; i++) {

int savePrev1 = prev1;

prev1 = prev2;

prev2 = savePrev1 + prev2;

}

return prev1;

}

public void run() {

for (int i=0; i<=15; i++)

println("F"+i+"="+fib(i)+", ");

}

}

Can somebody explain me this bit plz:

public static int fib(int n) {

int prev1=0, prev2=1;

for(int i=0; i<n; i++) {

int savePrev1 = prev1;

prev1 = prev2;

prev2 = savePrev1 + prev2;

}

return prev1;

thanks alot dudes.