lab fab
package lab7;public class Fibonacci {
private static int aNumber = 1;
private static int bNumber = 1 ;
private static int cNumber=0;
public static int next()
{
cNumber = aNumber + bNumber;
aNumber = bNumber;
bNumber =cNumber ;
return (cNumber);
}
public static void main(String[] args) {
Fibonacci.next();
System.out.println( "1 :"+cNumber);
Fibonacci.next();
System.out.println( "2 :"+cNumber);
Fibonacci.next();
System.out.println( "3 :"+cNumber);
Fibonacci.next();
System.out.println( "4 :"+cNumber);
Fibonacci.next();
System.out.println( "5 :"+cNumber);
System.gc(); }
}
0 Comments:
張貼留言
<< Home