📄 test.java
字号:
public class Test
{
public static void main(String[] args)
{
System.out.println("递归的使用!");
System.out.println("阶乘:");
System.out.println(f(5));
System.out.println("斐波那契数列第n个位置上的数值:");
System.out.println(f1(5));
}
static int f(int a) //如果前面不加上static 会出现“无法从静态上下文中引用非静态方法”错误
{
if(a==1)return 1;
else
return a*f(a-1);
}
public static int f1(int n)
{
if(n==1||n==2)
return 1;
else
return f1(n-1)+f1(n-2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -