/* 编程实现费氏数列的计算并打印 */ public class F { //自定义成员方法实现费氏数列中第n项数值的计算并返回,n由参数指定 int show(int n) { //递归计算 if(n == 1 || n == 2) { return 1; } return show(n-1)+show(n-2); } public static void main(String[] args) { F f = new F(); int n = f.show(5); System.out.println(n); } }